MATLAB: Circshift Odd Rows by one

circshiftodd rows

I have a matrix Z that is (5,6) and I would like to circshift only its odd rows by 1. Any advice on how that can be done? Thanks!

Best Answer

Trivially?
A = magic(7)
A =
30 39 48 1 10 19 28
38 47 7 9 18 27 29
46 6 8 17 26 35 37
5 14 16 25 34 36 45
13 15 24 33 42 44 4
21 23 32 41 43 3 12
22 31 40 49 2 11 20
A(1:2:end,:) = circshift(A(1:2:end,:),1,2)
A =
28 30 39 48 1 10 19
38 47 7 9 18 27 29
37 46 6 8 17 26 35
5 14 16 25 34 36 45
4 13 15 24 33 42 44
21 23 32 41 43 3 12
20 22 31 40 49 2 11