MATLAB: Put each column of a matrix into different cells

cellmat2cellMATLAB

I have a matrix of size (4×4)
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 {4×1} or {1×4} 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

Best Answer

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}