Circshift Odd Rows by one

2 views (last 30 days)
Vass Kap
Vass Kap on 11 May 2015
Edited: John D'Errico on 11 May 2015
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!

Accepted Answer

John D'Errico
John D'Errico on 11 May 2015
Edited: John D'Errico on 11 May 2015
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

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!