Switch two row of matrix
古いコメントを表示
How to switch two row of matrix? For example: matrix A is: 1 3 4; 2 4 5 and Y want to be 2 4 5; 1 3 4 ?
3 件のコメント
Nikhil Sachan
2019 年 2 月 1 日
temp=A(2,:);
A(1,:)=A(2,:);
A(2,:)=temp;
%this will swap required rows
madhan ravi
2019 年 2 月 21 日
編集済み: madhan ravi
2019 年 2 月 21 日
A more efficient answer had been accepted 5 years ago.
Tristan McRae
2019 年 2 月 22 日
omg savage
採用された回答
その他の回答 (1 件)
Pontus Vikstål
2019 年 8 月 12 日
編集済み: Pontus Vikstål
2019 年 8 月 12 日
This way might be even faster.
A = [1 3 4; 2 4 5]
x = [0 1;1 0];
A = x*A
Then there's also this way
A = [1 3 4; 2 4 5]
A = flip(A)
2 件のコメント
madhan ravi
2020 年 7 月 25 日
If A has more than two rows this won’t work.
Luis Mendez Lopez
2020 年 9 月 22 日
Yeah i will do that with my 600*600 matrix
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!