how to split and transpose a cell array?

Hi !! I have the next cell composition (30*1 size)
What I want to do is to split it first, according to the "," so each different number has to occupy a diffierent column. Like this:
After this, I want to transpose all the numbers, so I want to have a final matrix size (7*30)
Can anyone help me to solve this?
Thanks in advance!

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 29 日

0 投票

a={'12,13,14,45';'4,8,nan,nan';'450,2,14,nan'}
out=cell2mat(cellfun(@(x) str2num(strrep(x,',',' ')),a,'un',0))'

4 件のコメント

Viridiana  Torres
Viridiana Torres 2016 年 4 月 29 日
Thanks Azzi but it is not working it says : Warning: Inputs must be character arrays or cell arrays of strings. > In @(x)str2num(strrep(x,',',' ')) Error using str2num (line 33) Requires string or character array input.
Error in @(x)str2num(strrep(x,',',' '))
Because a is a cell array but made by numbers.
Any idea how to correct this?
Thanks!
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 29 日
Viridiana commented
Also @Azzi Abdelmalek when I run your code I have the next matrix as output.
out =
12 13 14 45
4 8 NaN NaN
450 2 14 NaN
But what I want is something like this:
New=
12 4 450
13 8 2
14 NaN 14
45 NaN NaN
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 29 日
編集済み: Azzi Abdelmalek 2016 年 4 月 29 日
This is not a problem, you know how to transpose a matrix?
out=out'
Now, for your previous comment, please post an example. It seems that your data are not similar to my example.
Viridiana  Torres
Viridiana Torres 2016 年 4 月 30 日
Thanks Azzi, these are some of the components in my a (as you call it in your example):
[199001021000.000,199001021005.000,199001021010.000,199001021015.000,199001031004.000,199001031009.000,199001031014.000]
[199001021001.000,199001021006.000,199001021011.000,199001031000.000,199001031005.000,199001031010.000,199001031015.000]
[199001021002.000,199001021007.000,199001021012.000,199001031001.000,199001031006.000,199001031011.000,NaN]
[199001021003.000,199001021008.000,199001021013.000,199001031002.000,199001031007.000,199001031012.000,NaN]

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNumeric Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by