How to convert cell array into numerical array correctly with precision(no roundup value)?
Show older comments
Hello,
I need to convert cell array into numerical array correctly with precision(no roundup value). I have tried various ways to get it right but couldn't. Any help is much appreciated.
Input:
L = {'38.95676800902' '38.95676807489' '38.95676821300' '38.95676838920' '38.95676853021'}
Desired output:
L_out= [38.95676800902 38.95676807489 38.95676821300 38.95676838920 38.95676853021]
*I used three methods but I am not getting it right,
1: Using cell2mat %This shows the output I got in Char instead of double(number), I am collecting output using counter in this case as it shows only one value instead of array when used this function.
L_out =
33333
88888
.....
99999
55555
66666
77777
66666
88888
00235
07183
94390
08022
29001
2: Using printf and scanf
S = sprintf('%s ', L{:}); L_out = double(sscanf(S, '%f'));
L_out = [38.9567 38.9567 38.9567 38.9567 38.9567]
This one is not accurate at all for my purpose
3. Using str2double
L_out = [38.9567 38.9567 38.9567 38.9567 38.9567]
In this way again I am not getting it accurate.
Is there a way to get it right?
Accepted Answer
More Answers (0)
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!