Reshaping a matrix using a loop or any function inbuilt.

5 views (last 30 days)
Hello, Does anyone know how to reshape a m*n matrix into m*1*n matrix using loops or any other function. I would definitely appriciate if both the methods are illustrated.

Accepted Answer

Jan on 21 Mar 2013
Edited: Jan on 21 Mar 2013
x = rand(3,4);
y = reshape(x, 3, 1, 4);
This is such efficient, that it is hard to dare to do this in a loop. Therefore I assume, that the problem is a homework question and to avoid cheating, I ask you to post, what you have done so far to solve it with a loop. Then ask a specific question to the occurring problems.
maharaj on 21 Mar 2013
I have a code which computes J matrix which is m*n and now i would want to change it into 3D m*1*n so that I can improve the quality of my image reconxstruction.

Sign in to comment.

More Answers (1)

Wouter on 21 Mar 2013
a suggestion: permute(matrix,[1 3 2])
this switches dimension 2 and 3 and effectively changes the size of your matrix
  1 Comment
Jan on 21 Mar 2013
This uses the clearly documented but confusing fact, that in Matlab missing trailing dimensions are assume to be 1 by default.

Sign in to comment.


Find more on Creating and Concatenating Matrices in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!