MATLAB: How to transform a matrix in his snake version

matrix

I'd want the code that transforms the matrix from
A=[1 2 3; 4 5 6; 7 8 9; 10 11 12]
to the matrix
B=[1 2 3; 6 5 4; 7 8 9; 12 11 10]
thanks

Best Answer

>> A=[1 2 3; 4 5 6; 7 8 9; 10 11 12];
B=[1 2 3; 6 5 4; 7 8 9; 12 11 10]
A([2:2:size(A,1)],:)=fliplr(A([2:2:size(A,1)],:));
result=A
isequal(result,B) % to check if you get the desired result
B =
1 2 3
6 5 4
7 8 9
12 11 10
result =
1 2 3
6 5 4
7 8 9
12 11 10
ans =
logical
1
>>