Switch two row of matrix
Afficher commentaires plus anciens
How to switch two row of matrix? For example: matrix A is: 1 3 4; 2 4 5 and Y want to be 2 4 5; 1 3 4 ?
3 commentaires
Nikhil Sachan
le 1 Fév 2019
temp=A(2,:);
A(1,:)=A(2,:);
A(2,:)=temp;
%this will swap required rows
madhan ravi
le 21 Fév 2019
Modifié(e) : madhan ravi
le 21 Fév 2019
A more efficient answer had been accepted 5 years ago.
Tristan McRae
le 22 Fév 2019
omg savage
Réponse acceptée
Plus de réponses (1)
Pontus Vikstål
le 12 Août 2019
Modifié(e) : Pontus Vikstål
le 12 Août 2019
This way might be even faster.
A = [1 3 4; 2 4 5]
x = [0 1;1 0];
A = x*A
Then there's also this way
A = [1 3 4; 2 4 5]
A = flip(A)
2 commentaires
madhan ravi
le 25 Juil 2020
If A has more than two rows this won’t work.
Luis Mendez Lopez
le 22 Sep 2020
Yeah i will do that with my 600*600 matrix
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!