MATLAB Answers

0

Replace the elements of a matrix

Asked by skinny pete on 9 Jun 2019
Latest activity Commented on by Walter Roberson
on 9 Jun 2019
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

  0 Comments

Sign in to comment.

3 Answers

Answer by per isakson
on 9 Jun 2019
Edited by per isakson
on 9 Jun 2019
 Accepted Answer

One way
z = permute( A, [2,1] );
B = z(:);
or
z = permute( A, [2,1] );
B = reshape( z, [],1 );

  1 Comment

Thank you per.

Sign in to comment.


Answer by TADA
on 9 Jun 2019

B = reshape(A',numel(A),1)

  1 Comment

A' is only correct for real valued entries, as it is the conjugate transpose.

Sign in to comment.


Answer by Walter Roberson
on 9 Jun 2019

B = reshape(A.',[],1);

  0 Comments

Sign in to comment.