how to split cell array values into two columns?
이전 댓글 표시
I've a variable in cell array as

[2.13949546690144;56.9515770543056] [1.98550875192835;50.4110852121618] . . . . . I want to split it into two columns with two decimal-point numbers as
2.13 56.95
1.98 50.41
.
.
.
by removing open, close braces and semicolon such as [ ; ]
답변 (1개)
KL
2017년 12월 5일
one way:
C = {[2.13949546690144;56.9515770543056]};
A = round([C{:}].'*100)/100
A =
2.1400 56.9500
댓글 수: 8
Prasanna
2017년 12월 5일
KL
2017년 12월 5일
how to do with this?
that's what I just showed you, did you try?
C = {[2.13949546690144;56.9515770543056];
[2.13949546690144;56.9515770543056];
[2.13949546690144;56.9515770543056];
[2.13949546690144;56.9515770543056]};
C = round([C{:}].'*100)/100
and the answer is,
C =
2.1400 56.9500
2.1400 56.9500
2.1400 56.9500
2.1400 56.9500
Prasanna
2017년 12월 5일
KL
2017년 12월 5일
Are you sure all your cells contain 2x1 vectors? Show me the output for,
C_sz = cell2mat(cellfun(@size,C,'uni',0))
and another thing, instead of attaching a screenshot of very poor resolution, attach your data directly (as an m-file, mat-file or a csv file, use the paperclip icon!)
Prasanna
2017년 12월 5일
yes, all cells are 2x1...
No, first element is 1x2! Your problem is right there! You somehow changed the first element in the cell array to be a row vector (1x2 size). Probably you tried my solution just for one element and then you wanted to do the rest.
Change it back to 2x1 and try again.
aima1{1} = aima1{1}.';
and then try my solution again,
>> C = round([aima1{:}].'*100)/100
C =
2.1300 56.9500
1.9900 50.4100
1.7100 50.6300
2.0300 50.3000
1.9800 45.0000
2.0300 45.0500
2.0800 45.0700
2.1400 45.0400
...
Prasanna
2017년 12월 5일
KL
2017년 12월 5일
My pleasure!
카테고리
도움말 센터 및 File Exchange에서 Managing Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
