matlab - Convert a cell of strings to a matrix of numbers -
i'm trying convert cell of numbers of different lengths matrix of numbers. i'm new matlab cells. apologize in advance if question sucks. i've done homework, last resort.
x
cell of strings. want these strings converted numbers. there way convert cell matrix without brute force iteration?
i've tried cell2mat
matlab freaks out. i've tried str2num
matlab freaks out. i've googled "converting cell of strings matrix of numbers", nothing comes up.
here's cell:
>>x x = '0' '850' '10483' '16039' '25670' '31242' '37009' '41023' '46798' '51881' '61491' '67181' '72941' '76163' '85759' '96654' '102439' '104615' '114224' >>class(x) ans = cell
you want str2double
:
x = {'1';'12';'3.14'}; y = str2double(x)
which returns
y = 1.000000000000000 12.000000000000000 3.140000000000000
the reason mat2cell
didn't work because numeric strings of different lengths. , str2num
doesn't permit cell inputs. might read , doc str2num
other reasons why str2double
better anyways.
Comments
Post a Comment