MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
Asked by maharaj on 21 Mar 2013

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.

Answer by Jan Simon on 21 Mar 2013

Edited by Jan Simon on 21 Mar 2013

Accepted answer

x = rand(3,4); y = reshape(x, 3, 1, 4); size(y)

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

No its is not a homework problem. It is a code i have been trying to modify to fit into my use.

Answer by 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

## 0 Comments