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
KL 2017 年 12 月 5 日

0 投票

one way:
C = {[2.13949546690144;56.9515770543056]};
A = round([C{:}].'*100)/100
A =
2.1400 56.9500

8 件のコメント

Prasanna
Prasanna 2017 年 12 月 5 日
I've cell array like this
how to do with this?
KL
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
Prasanna 2017 年 12 月 5 日
it shows the error as
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
KL
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
Prasanna 2017 年 12 月 5 日
yes, all cells are 2x1. find the attachment for 2x1 data (aima1). the above code doesnot give correct ans; find its output in (C_sz)
KL
KL 2017 年 12 月 5 日
編集済み: KL 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
Prasanna 2017 年 12 月 5 日
It works. thank you very much!!.
KL
KL 2017 年 12 月 5 日
My pleasure!

サインインしてコメントする。

タグ

質問済み:

2017 年 12 月 5 日

コメント済み:

KL
2017 年 12 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by