How do you vertically concatenate the rows of a cell array consisting of vectors of numbers?
30 次查看(过去 30 天)
显示 更早的评论
I want to vertically concatenate the elements of a cell array so that, for example, an array that is 3 x 9 becomes 1 x 9. How do I do that? The following concatenates everything into one dimension, which isn't what I want:
vertcat(cellarray{:});
2 个评论
the cyclist
2022-3-30
What you want to do is not clear to me. Can you upload the cell array (using the paperclip icon in the INSERT section of the toolbar), or perhaps just write code here to define an smaller (like 3x2) input, and what you expect the output to be?
The best method will likely depend on whether the cell elements are numeric, strings, character arrays, etc.
采纳的回答
per isakson
2022-3-30
Example
m = magic(3);
m = [m,m,m];
cac = num2cell(m); % sample data
arrayfun( @(ix) vertcat(cac{:,ix}), [1:9], 'uni',false )
Is this what you look for?
更多回答(2 个)
Walter Roberson
2022-3-30
Output = arrayfun(@(ColIdx) vertcat(YourCell{:,ColIdx}), 1:size(YourCell,2), 'uniform', 0);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!