How to split cell array separated by ',' into double array?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ahmed Hamed
am 29 Apr. 2016
Kommentiert: Tobias Bramminge
am 1 Okt. 2019
I have a cell array (2x1) as follows
'0,0,0,2,2,0.39,0.49'
'0,1,2,2,2,0.34,0.44'
I need to split it into double array (2x7) so the output be as follows
0 0 0 2 2 0.39 0.49
0 1 2 2 2 0.34 0.44
Is this possible? if yes? any suggestions please?
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 29 Apr. 2016
Bearbeitet: Azzi Abdelmalek
am 29 Apr. 2016
a={'0,0,0,2,2,0.39,0.49'
'0,1,2,2,2,0.34,0.44'}
out=cell2mat(cellfun(@str2num,strrep(a,',',' '),'un',0))
Weitere Antworten (1)
dpb
am 29 Apr. 2016
>> c={'0,0,0,2,2,0.39,0.49'
'0,1,2,2,2,0.34,0.44'};
>> str2num(char(c))
ans =
0 0 0 2.0000 2.0000 0.3900 0.4900
0 1.0000 2.0000 2.0000 2.0000 0.3400 0.4400
>>
3 Kommentare
dpb
am 29 Apr. 2016
Intended to ask--how did you get such a format instead of the numeric values in the first place?
Tobias Bramminge
am 1 Okt. 2019
Hi! I am using this solution now, but of some reason, a few of my rows are deleted with the function.
Anybody familier with this problem?
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!