Reshape - columnwise. any command to linewise?

help reshape
RESHAPE Reshape array.
RESHAPE(X,M,N) returns the M-by-N matrix whose elements are taken columnwise from X.
I need some way to turn a matrix linewise instead.

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 29 de Nov. de 2011
reshape(X.',M,N).'

8 comentarios

Vasco
Vasco el 29 de Nov. de 2011
tytyty. =)
Giacomo Perantoni
Giacomo Perantoni el 21 de Feb. de 2019
The transpose operator may be expensive for a large matrix. Is there an alternative way to solve the original problem without the additional computational cost?
winkmal
winkmal el 14 de En. de 2020
Should M and N not be switched in your command?
Amir
Amir el 18 de Feb. de 2020
M and N should be switched to return the M-by-N matrix.
The command should be reshape(X.',N,M).'
Med Aymane Ahajjam
Med Aymane Ahajjam el 18 de Feb. de 2020
Life saver!!! Thank you!
sohaib bhatti
sohaib bhatti el 30 de Ag. de 2021
How can the same be done if X is a 3d matrix?
Loïc Niederhauser
Loïc Niederhauser el 26 de Abr. de 2022
Also, what if I want to reshape to a 3d matrix? Is there anyway to just work row major in matlab?
Loic -Hi btw ;-) - you could use permute for ND-array (there is also pagetranspose command more restrictive)
X=randi(9,[6 5])
X = 6×5
1 2 4 9 1 9 1 7 8 1 5 6 6 4 8 4 2 7 8 2 2 4 5 5 9 7 1 7 1 8
permute(reshape(X.',[size(X,2) 2 3]),[2 1 3])
ans =
ans(:,:,1) = 1 2 4 9 1 9 1 7 8 1 ans(:,:,2) = 5 6 6 4 8 4 2 7 8 2 ans(:,:,3) = 2 4 5 5 9 7 1 7 1 8

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 29 de Nov. de 2011

Comentada:

el 26 de Abr. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by