How to split a cell array?
4 ビュー (過去 30 日間)
古いコメントを表示
Hello!
Be
Z={'1.1 2.1 3.2 3.3 5.5 5.4'; '3 4 5 10 11 56'};
a 2*1 cell array.How can I split Z into a cell array with 2x6 cells? Notice that Z is composed by numbers.
Thanks a lot.
0 件のコメント
採用された回答
Stephen23
2016 年 4 月 25 日
編集済み: Stephen23
2016 年 4 月 25 日
Option One: Convert to Numeric
>> mat = [sscanf(Z{1},'%f'),sscanf(Z{2},'%f')].'
mat =
1.1000 2.1000 3.2000 3.3000 5.5000 5.4000
3.0000 4.0000 5.0000 10.0000 11.0000 56.0000
Best would be to leave it as a numeric array... however if you really need a cell array of numeric scalars, then use num2cell:
num2cell(mat)
Option Two: Keep as String
>> tmp = regexp(Z,'\S+','match');
>> tmp = vertcat(tmp{:})
tmp =
'1.1' '2.1' '3.2' '3.3' '5.5' '5.4'
'3' '4' '5' '10' '11' '56'
4 件のコメント
Stephen23
2016 年 4 月 26 日
編集済み: Stephen23
2016 年 4 月 26 日
@angelavtc: That example with numeric vectors inside a cell array cannot be trivially converted to a single array with each numeric element in its own cell, because you have different number of elements in each vector. You could try experimenting with these FEX submissions:
inp = {[...],[...]}
out = padcat(inp{:})
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!