How to flip every 5th row and column in matrix

1 次查看(过去 30 天)
For exaple I have
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8
9 9 9
10 10 10
11 11 11
12 12 12
and I need to get
1 1 1
2 2 2
3 3 3
6 6 6
5 5 5
4 4 4
7 7 7
8 8 8
9 9 9
12 12 12
11 11 11
10 10 10
If I have matrix 12x3 and I divide it in 4 smaller matrix, I have to flip rows in every other matrix. I hope you got what I need.
  1 个评论
Dennis
Dennis 2018-7-4
A=[1 1 1; 2 2 2; 3 3 3; 4 4 4; 5 5 5; 6 6 6; 7 7 7; 8 8 8; 9 9 9; 10 10 10; 11 11 11; 12 12 12];
for k=0:1
A(k*6+4:k*6+6,1:3)=A(k*6+6:-1:k*6+4,1:3)
end

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2018-7-4
编辑:Stephen23 2018-7-4
>> M = repmat((1:12).',1,3)
M =
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8
9 9 9
10 10 10
11 11 11
12 12 12
>> M([4:6:end,6:6:end],:) = M([6:6:end,4:6:end],:)
M =
1 1 1
2 2 2
3 3 3
6 6 6
5 5 5
4 4 4
7 7 7
8 8 8
9 9 9
12 12 12
11 11 11
10 10 10

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by