splitting Cell array in a loop
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I want to split X into Y, a 1 x 4 cell. Y will be {[1:8]} {[9:16]} {[17:24]} {[25 32]}. thanks.
X = 1:32;
Y = cell (1,4);
for j = [1,9,17,25];
for i = 1: 4
Y{1,i} = X (j:j+7);
end
end
Akzeptierte Antwort
Voss
am 29 Aug. 2022
X = 1:32;
Y = cell(1,4);
j = [1,9,17,25];
for i = 1:numel(j)
Y{1,i} = X(j(i):j(i)+7);
end
disp(Y)
Or:
Y = num2cell(reshape(X,[],4).',2).'
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!