How to combine cell arrays to form one nested cell array entry
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Voss
on 21 May 2024
% 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}
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!