Azzera filtri
Azzera filtri

How to combine cell arrays to form one nested cell array entry

20 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

Voss
Voss il 21 Mag 2024 alle 21:00
% 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 = 4x3 cell array
{1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell} {1x2 cell}
X{1,1},X{1,2},X{1,3}
ans = 1x2 cell array
{[1]} {[2]}
ans = 1x2 cell array
{[3]} {[4]}
ans = 1x2 cell array
{[5]} {[6]}
N = size(X,1);
Y = cell(N,1);
for ii = 1:N
Y{ii} = vertcat(X{ii,:});
end
X = Y;
X
X = 4x1 cell array
{3x2 cell} {3x2 cell} {3x2 cell} {3x2 cell}
X{1}
ans = 3x2 cell array
{[1]} {[2]} {[3]} {[4]} {[5]} {[6]}

Più risposte (0)

Categorie

Scopri di più su Data Types in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by