A = [1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15; 16 17 18 19 20], mover = 2
[m,n] = size(A); i0 = [(1:m)';(2:n)'*m;m*n - (1:m-1)';(n-2:-1:1)'*m+1];
A = a; A(i0) = A(circshift(i0,-mover)) A(i0) = A(circshift(i0,mover)) %come back
A = [1 2 3 4 5; 6 7 8 9 10; 11 12 13 14 15; 16 17 18 19 20], mover = 2
[m,n] = size(A); i0 = [(1:m)';(2:n)'*m;m*n - (1:m-1)';(n-2:-1:1)'*m+1];
A = a; A(i0) = A(circshift(i0,-mover)) A(i0) = A(circshift(i0,mover)) %come back
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!