About row and column swapping in a matrix
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mohammad
le 22 Juil 2015
Commenté : Rakib Seemanto
le 1 Nov 2020
Hi Guys. I have a question which probably could be easy or might have built in function but I kinda stuck on it. Attached is a 3x3 matrix as an image as appeared below. I want to swap the rows and columns as shown here and save each sequence of swapping. I have a very big file to handle, i have just shown a small sample here. I tried with a loop but could not get it working. I would greatly appreciate any efforts.
Thanks Rafiq
0 commentaires
Réponse acceptée
Star Strider
le 22 Juil 2015
Modifié(e) : Star Strider
le 22 Juil 2015
I would just use circshift:
A = [0 1 2; 1 1.4 2.2; 2 2.2 2.8];
B = circshift(A, [-1 -1])
B =
1.4 2.2 1
2.2 2.8 2
1 2 0
5 commentaires
Rakib Seemanto
le 1 Nov 2020
how can I swap 6x6 matrix middle two rows.A = [ 1 2 3;4 5 6;7 8 9;10 11 12;13 14 15;16 17 18]
The output will be:B = [ 1 2 3;4 5 6;10 11 12;7 8 9;13 14 15;16 17 18]
Plus de réponses (1)
Walter Roberson
le 22 Juil 2015
To swap column J with column K you would use
newArray = oldArray;
newArray(:,[K J]) = newArray(:,[J K]];
For swapping rows,
newArray([K J],:) = newArray([J K],:);
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!