フィルターのクリア

How to flip only some rows inside a matrix?

1 回表示 (過去 30 日間)
Muniba Shah
Muniba Shah 2018 年 10 月 27 日
コメント済み: madhan ravi 2018 年 10 月 31 日
hey all, if i have vector
A=[2 5 6 7 8 9]
i need it to become a matrix
A=[2 9;
5 8;
7 6]
any suggestions?
  1 件のコメント
the cyclist
the cyclist 2018 年 10 月 27 日
I don't understand the general rule for going from the vector to the matrix. Can you describe it?

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

採用された回答

madhan ravi
madhan ravi 2018 年 10 月 27 日
A=[2 5 6 7 8 9]
a=fliplr(reshape(A,[3 2]))
a([3 1])= a([1 3])
a=fliplr([a(1:2,:);flip(a(3,:))])
  2 件のコメント
Abdul Rehman
Abdul Rehman 2018 年 10 月 27 日
編集済み: Abdul Rehman 2018 年 10 月 27 日
that good one Madhan Sir.
madhan ravi
madhan ravi 2018 年 10 月 31 日
Thank you @Abdul

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

その他の回答 (2 件)

Abdul Rehman
Abdul Rehman 2018 年 10 月 27 日
編集済み: Abdul Rehman 2018 年 10 月 27 日
i have got Answer for you but its not generic for all matrix.you should look for the end and first element of matrix.
Hopefully it's work for you...
if true
A=[2 5 6 7 8 9];
b=(size(A));
[r c]=size(A);
j=1;
gg=c;
for u=c:-1:c-1 %two iteration for size of vector.
if(j==1)
b(j)=A(j); % first value at start
end
if(gg==c)
b(gg)=A(gg/2); %Size of vector divided by 2 center value at end
end
j=j+1;
b(j)=A(u);
b(j+1)=A(j);
j=j+1;
end
b=reshape(b,[2 3])
end
Here Answer:

Muniba Shah
Muniba Shah 2018 年 10 月 31 日
A = [2 5 6 7 8 9]; B = reshape(A,[3,2]); C=flipud(B(:,2)); B(:,2)=C; D=fliplr(B(3,:)); B(3,:)=D

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by