Filter löschen
Filter löschen

put each column of a matrix into different cells

12 Ansichten (letzte 30 Tage)
ARN
ARN am 11 Mai 2020
Bearbeitet: Mehmed Saad am 11 Mai 2020
I have a matrix of size (4x4)
a = [1 2 3 4; 123 4 5 6; 52 5 4 7; 2 5 8 7];
b = mat2cell(a, ?)
I want b to be a {4x1} or {1x4} cell where every cell contains the column values of matrix
b = cell{1,:} = [1; 123; 52; 2] , cell{2,:} = [2 ; 4 ; 5 ; 5] and so on. but i am not being able to figure out mat2cell input parameters

Akzeptierte Antwort

Mehmed Saad
Mehmed Saad am 11 Mai 2020
Bearbeitet: Mehmed Saad am 11 Mai 2020
Use num2cell. it is easy
a = [1 2 3 4; 123 4 5 6; 52 5 4 7; 2 5 8 7];
b = num2cell(a,1)
b =
1×4 cell array
{4×1 double} {4×1 double} {4×1 double} {4×1 double}

mat2cell

is usefulll for other purpose
b = mat2cell(a.',[1 1 1 1])
b =
1×4 cell array
{4×1 double} {4×1 double} {4×1 double} {4×1 double}

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by