How to split cell array separated by ',' into double array?

조회 수: 5 (최근 30일)
Ahmed Hamed
Ahmed Hamed 2016년 4월 29일
댓글: Tobias Bramminge 2019년 10월 1일
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?

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 29일
편집: Azzi Abdelmalek 2016년 4월 29일
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))

추가 답변 (1개)

dpb
dpb 2016년 4월 29일
>> 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
dpb
dpb 2016년 4월 29일
Intended to ask--how did you get such a format instead of the numeric values in the first place?
Tobias Bramminge
Tobias Bramminge 2019년 10월 1일
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by