MATLAB cell to matrix
古いコメントを表示
I have 1 row and 106 columns. Each cell contains various numbers. Some cells contain 1 number, some contain 5, etc. The problem is this: If one number is present, it looks great. Some cells have more than one number. I would like for the second number to go in the second row, third number in third row, etc. I am not sure how to do this. I am guessing I need to make a zeros matrix or something but I am not sure
6 件のコメント
Azzi Abdelmalek
2014 年 1 月 13 日
If M={1 [7 8] 3 [ 1 5 6] 0 [1 5 8] 2 10 }
What is the expected result?
Benjamin Cowen
2014 年 1 月 13 日
Azzi Abdelmalek
2014 年 1 月 13 日
You can simply post the expected result, if really you know what you want
Benjamin Cowen
2014 年 1 月 13 日
Benjamin Cowen
2014 年 1 月 13 日
Benjamin Cowen
2014 年 1 月 13 日
採用された回答
その他の回答 (1 件)
Matt J
2014 年 1 月 13 日
Is this what you want?
>> C={5,[6 7 8], [9,10]};
>>cell2mat(C)
ans =
5 6 7 8 9 10
Or,
>> [C{:}]
ans =
5 6 7 8 9 10
6 件のコメント
Benjamin Cowen
2014 年 1 月 13 日
Matt J
2014 年 1 月 13 日
C={5,[6 7 8], [9,10]};
M=max(cellfun('length',C));
result = cell2mat(cellfun(@(c) pad(c,M), C, 'uni',0)),
function c=pad(c,M)
c=c(:);
c(M+1,1)=0;
c(end)=[];
end
Benjamin Cowen
2014 年 1 月 13 日
Benjamin Cowen
2014 年 1 月 13 日
Matt J
2014 年 1 月 13 日
Yes. That is one of your options.
カテゴリ
ヘルプ センター および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!