Rearrange matrix into single row

14 views (last 30 days)
Lanceric Tse
Lanceric Tse on 10 Aug 2018
Edited: Stephen23 on 10 Aug 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]?

Accepted Answer

Paul Shoemaker
Paul Shoemaker on 10 Aug 2018
reshape(b',1,numel(b)) % Note the transpose ('), this is important.
  1 Comment
Stephen23
Stephen23 on 10 Aug 2018
Edited: Stephen23 on 10 Aug 2018
This answer uses complex transpose. See James Tursa's answer for the correct solution for all cases.

Sign in to comment.

More Answers (1)

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

Tags

Community Treasure Hunt

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

Start Hunting!