how to split cell array values into two columns?
Show older comments
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 [ ; ]
Answers (1)
KL
on 5 Dec 2017
one way:
C = {[2.13949546690144;56.9515770543056]};
A = round([C{:}].'*100)/100
A =
2.1400 56.9500
8 Comments
Prasanna
on 5 Dec 2017
KL
on 5 Dec 2017
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
on 5 Dec 2017
KL
on 5 Dec 2017
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
on 5 Dec 2017
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
on 5 Dec 2017
KL
on 5 Dec 2017
My pleasure!
Categories
Find more on Managing Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!