フィルターのクリア

Reversing every second row in a matrix

19 ビュー (過去 30 日間)
Melissa2305
Melissa2305 2015 年 12 月 19 日
コメント済み: Melissa2305 2015 年 12 月 19 日
Hello!
I have a question regarding matrix transformation. The simplified version of what I have is:
1 2 3
4 5 6
7 8 9
10 11 12
etc
What I want is that every second row is reversed, so resulting in:
1 2 3
6 5 4
7 8 9
12 11 10
I have tried the flip-function, but as far as I found out that reverses every row. Any idea how to do this?
Thanks!

採用された回答

the cyclist
the cyclist 2015 年 12 月 19 日
M = [ 1 2 3;
4 5 6;
7 8 9;
10 11 12];
M(2:2:end,:) = fliplr(M(2:2:end,:))
  1 件のコメント
Melissa2305
Melissa2305 2015 年 12 月 19 日
This was exactly what I was looking for :) Thanks!

サインインしてコメントする。

その他の回答 (2 件)

Star Strider
Star Strider 2015 年 12 月 19 日
This works:
M = [1 2 3
4 5 6
7 8 9
10 11 12];
M(2:2:end,:) = M(2:2:end, end:-1:1);

harjeet singh
harjeet singh 2015 年 12 月 19 日
dear melissa use this code
clear all
close all
clc
a=[1 2 3;4 5 6;7 8 9;10 11 12];
for i=1:size(a,1)
if(mod(i,2)==0)
b(i,:)=(flipud(a(i,:)'))';
else
b(i,:)=a(i,:);
end
end
b

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by