MATLAB: How to permute the rows and columns in a matrix

matrix

for example: I have matrix A: A = [1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16] how to permute between column 1 and column 4 ? how to permute between row 1 and row 3 ? thanks

Best Answer

Swapping the columns
idx = [4 2 3 1];
B = A(:,idx);
Swapping the rows
idx = [3 2 1 4];
C = A(idx,:);