Rearrange matrix into single row

12 visualizaciones (últimos 30 días)
Lanceric Tse
Lanceric Tse el 10 de Ag. de 2018
Editada: Stephen23 el 10 de Ag. de 2018
Hey there, I have a matrix that looks like this
b=1 2 3 4
1 2 3 4
1 2 3 4
What do I have to do to arrange it into a single row vector[ 1 2 3 4 1 2 3 4 1 2 3 4]?

Respuesta aceptada

Paul Shoemaker
Paul Shoemaker el 10 de Ag. de 2018
reshape(b',1,numel(b)) % Note the transpose ('), this is important.
  1 comentario
Stephen23
Stephen23 el 10 de Ag. de 2018
Editada: Stephen23 el 10 de Ag. de 2018
This answer uses complex transpose. See James Tursa's answer for the correct solution for all cases.

Iniciar sesión para comentar.

Más respuestas (1)

James Tursa
James Tursa el 10 de Ag. de 2018
Editada: James Tursa el 10 de Ag. de 2018
result = reshape(b.',1,[]);
The transpose is needed to get the row values to line up in memory first before doing the reshape.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by