About row and column swapping in a matrix
Show older comments
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
Accepted Answer
More Answers (1)
Walter Roberson
on 22 Jul 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],:);
Categories
Find more on Creating and Concatenating Matrices 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!