Filling up a matrix
4 ビュー (過去 30 日間)
古いコメントを表示
I have an array of 69 x 1 cells. Every cell contains a matrix of either 12 x 1 or 13 x 1. I want Matlab to make a matrix of 13 x 69 and filling up the empty spaces of the 12 x 1 matrices by adding zero's.
Is this possible?
Thanks for the help!
0 件のコメント
回答 (2 件)
James Tursa
2015 年 9 月 28 日
How about a simple loop:
result = zeros(13,69);
for k=1:69
n = numel(mycellarray{k});
result(1:n,k) = mycellarray{k};
end
Walter Roberson
2015 年 9 月 29 日
first13 = @(V) V(1:13);
result = cell2mat( cellfun(@(V) first13([V;0]), YourCellArray, 'Uniform', 0) );
If the cells can be variable size all the way from empty to 13, then use
first13([V;zeros(13,1)])
2 件のコメント
Walter Roberson
2015 年 9 月 29 日
result = cell2mat( cellfun(@(V) first13([V;0]), YourCellArray, 'Uniform', 0).' );
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!