create cell from array with specified size
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gaetano Pavone
am 19 Dez. 2023
Bearbeitet: Voss
am 19 Dez. 2023
Hello,
Let mymatrix a 24x1 double, how is it possible to obtain a group as specified_sizex1 cell?
For example:
mymatrix=[1:24];
group={[mymatrix(1) mymatrix(2)],...}
0 Kommentare
Akzeptierte Antwort
Dyuman Joshi
am 19 Dez. 2023
Bearbeitet: Dyuman Joshi
am 19 Dez. 2023
Note that the specified size must completely divide the number of rows in the column vector -
mymatrix=[1:24].';
size(mymatrix)
%Total number of elements in the vector
n = numel(mymatrix);
%Specified size
ss1 = 2;
out1 = mat2cell(mymatrix, repelem(n/ss1, 1, ss1), 1)
%Example 2
ss2 = 4;
out2 = mat2cell(mymatrix, repelem(n/ss2, 1, ss2), 1)
0 Kommentare
Weitere Antworten (2)
Siehe auch
Kategorien
Mehr zu Array Geometries and Analysis 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!