Filter löschen
Filter löschen

How to flip every 5th row and column in matrix

1 Ansicht (letzte 30 Tage)
Matija Kosak
Matija Kosak am 4 Jul. 2018
Bearbeitet: Stephen23 am 4 Jul. 2018
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 Kommentar
Dennis
Dennis am 4 Jul. 2018
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 4 Jul. 2018
Bearbeitet: Stephen23 am 4 Jul. 2018
>> 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

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by