MATLAB: About row and column swapping in a matrix

row column swap

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 3×3 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

Best Answer

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