필터 지우기
필터 지우기

How to flip every 5th row and column in matrix

조회 수: 1 (최근 30일)
Matija Kosak
Matija Kosak 2018년 7월 4일
편집: Stephen23 2018년 7월 4일
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