MATLAB: How to convert each clolumn of a matrix to new matrix

matrix arraymatrix manipulation

|I have a matrix of m*n dimension and I want to reshape each column of this matrix to a new matrix of a*b dimension.I want to save such n distinct a*b matrices so that I can convolve each of this n matrix with some other functions.But I got errors in my code
for p=1:n
mat{p} = reshape(matrix{p},a,b)
end
Error using reshape
To RESHAPE the number of elements must not change.
  • I am new to to MATLAB and please help.Thanks in advance.

Best Answer

a = 5 ; b = 6 ;
matrix = rand(30,10) ;
[m,n] = size(matrix) ;
mat = cell(n,1) ;
if m == a*b
for p=1:n
mat{p} = reshape(matrix(:,p),a,b) ;
end
else
disp('you cannot reshape because number of elements changing')
end