Matrix elements movement in MATLAB

3 ビュー (過去 30 日間)
Raza
Raza 2014 年 2 月 19 日
コメント済み: Alina 2014 年 3 月 7 日
HI, I want to move the matrix elements as desired like
a=[1 2 3 4;
5 6 7 8;
9 10 11 12;
13 14 15 16]
now i want to make it
a=[3 4 8 7;
11 12 16 15;
14 13 9 10;
6 5 1 2]
how can i do it in MATLAB

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 2 月 19 日
編集済み: Azzi Abdelmalek 2014 年 2 月 19 日
a=[1 2 3 4;
5 6 7 8;
9 10 11 12;
13 14 15 16]
n=size(a,2);
n2=n/2;
a1=a(:,n2+1:n);
a2=a(:,1:n2);
a1(2:2:end,:)=fliplr(a1(2:2:end,:))
a2(2:2:end,:)=fliplr(a2(2:2:end,:))
a2=flipud(a2)
out=reshape([a1' a2'],n,[])'
  2 件のコメント
Raza Ali
Raza Ali 2014 年 3 月 2 日
what should be done to reverse this process means what to do, to get "a" back
[1 2 3 4;
5 6 7 8;
9 10 11 12;
13 14 15 16]
Alina
Alina 2014 年 3 月 7 日
the opposite of above coding can be used to convert this matrix back to its initial position
Am i right?

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by