Replace the elements of a matrix

1 view (last 30 days)
Hello everyone,
I have an A matrix as
A=[a b ; c d ; e f ; g h]
and want to get B matrix as
B=[a ; b; c; d; e; f; g; h]
using A matrix. How can I code it? Thanks

Accepted Answer

per isakson
per isakson on 9 Jun 2019
Edited: per isakson on 9 Jun 2019
One way
z = permute( A, [2,1] );
B = z(:);
or
z = permute( A, [2,1] );
B = reshape( z, [],1 );

More Answers (2)

TADA
TADA on 9 Jun 2019
B = reshape(A',numel(A),1)
  1 Comment
Walter Roberson
Walter Roberson on 9 Jun 2019
A' is only correct for real valued entries, as it is the conjugate transpose.

Sign in to comment.


Walter Roberson
Walter Roberson on 9 Jun 2019
B = reshape(A.',[],1);

Categories

Find more on Matrices and Arrays 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!