Replace the elements of a matrix

1 visualizzazione (ultimi 30 giorni)
skinny pete
skinny pete il 9 Giu 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

Risposta accettata

per isakson
per isakson il 9 Giu 2019
Modificato: per isakson il 9 Giu 2019
One way
z = permute( A, [2,1] );
B = z(:);
or
z = permute( A, [2,1] );
B = reshape( z, [],1 );

Più risposte (2)

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

Accedi per commentare.


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

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by