converting cell of strings in arry or cell of numbers
Ältere Kommentare anzeigen
I have a cell of strings 'tsince' having dimension 143 by 1 as '4632' '0.00000000' '-1440.00000000' '-1438.00000000' '-1436.00000000' '-1434.00000000' '-1432.00000000' '-1430.00000000' '-1428.00000000' . . . . '1436.00000000' '1438.00000000' '1440.00000000'
I want to convert it to an array or cell of numbers. I tried with str2num() but it gives the following error:
>> tsince2=str2num(tsince) ??? Error using ==> str2num at 33 Requires string or character array input.
I am new to matlab. somebody can please help out how to do this. Thanks in advance
Zohaib
Akzeptierte Antwort
Weitere Antworten (3)
Nirmal Gunaseelan
am 28 Dez. 2011
0 Stimmen
STR2NUM requires a single string to work on. You need to loop around the individual cell elements and use STR2NUM. CELLFUN is a better way of doing the same - check out the doc.
Matt Tearle
am 28 Dez. 2011
0 Stimmen
Try str2double(tsince)
Dao Austin
am 17 Apr. 2015
0 Stimmen
you may convert cell to char, then use str2num:
%given A;
C=char(A);
D=str2num(C);
Kategorien
Mehr zu Data Type Conversion finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!