How to combine cell arrays to form one nested cell array entry
3 次查看(过去 30 天)
显示 更早的评论
Hello, I have a variable (X) that is a cell array (size 64X634). In the each location of cell array X, there is a nested 1x2 cell array.
How can I combinethe nested 1x2 cell arrays across the 634 columns in X such that the variable(X) is now the desired size of 64x1, where each row entry of the cell arrray X contains the new 634x2 nested cell array?
In other words, I want to combine each of the 1x2 cell arrays found in the columns of the original variable(X) so that each row of variable(X) only has one column (now a nested cell array with all the original 1x2 nested cell arrays). Thanks!
0 个评论
采纳的回答
Voss
2024-5-21
% 4x3 instead of 64x634, for demonstration
X = { ...
{1 2} {3 4} {5 6}; ...
{7 8} {9 10} {11 12}; ...
{13 14} {15 16} {17 18}; ...
{19 20} {21 22} {23 24}; ...
};
X
X{1,1},X{1,2},X{1,3}
N = size(X,1);
Y = cell(N,1);
for ii = 1:N
Y{ii} = vertcat(X{ii,:});
end
X = Y;
X
X{1}
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!