swapping rows in a matrix
36 ビュー (過去 30 日間)
古いコメントを表示
How can i create a matrix which is a copy of an other matrix except 2 rows have to swap.
for example 4*4nmatrix called M how can i create an new matrix which is a copy of M, but the first and the third row are swapped
0 件のコメント
採用された回答
Stephen23
2019 年 11 月 26 日
>> X = [1,3]; % rows to swap
>> M = randi(9,4,5)
M =
6 7 6 2 9
2 3 2 1 1
1 6 9 7 9
4 6 7 5 2
>> W = M;
>> W(X,:) = W(X([2,1]),:)
W =
1 6 9 7 9
2 3 2 1 1
6 7 6 2 9
4 6 7 5 2
3 件のコメント
Adam Danz
2020 年 8 月 11 日
With the syntax W(X([A,B]),:) row A becomes row 1 and row B becomes row 2.
Indexing is lesson 1 in Matlab.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!