swap elements in a matrix
83 ビュー (過去 30 日間)
古いコメントを表示
Hello i want to swap elements in a matrix.I want to do it to elements of the same row and to elements of differents rows. Please help.Thank you
2 件のコメント
Adam
2015 年 3 月 20 日
An example would be useful, although the usual method for swapping elements is to use a temporary variable to store one while you copy the other over the top of it and then copy from the temporary variable into the 2nd location.
採用された回答
the cyclist
2015 年 3 月 20 日
編集済み: the cyclist
2018 年 5 月 10 日
% A matrix:
A = magic(3);
% Swap the first and second elements of the first column:
A([1 2]) = A([2 1])
% Swap the first and second elements of the third column:
A([7 8]) = A([8 7])
% Swap the first and third elements of the first row:
A([1 7]) = A([7 1])
4 件のコメント
YANAN ZHU
2018 年 5 月 9 日
A([1 7]) = A([7 1]) actually swap the first and third elements of the first row, not "Swap the first and second elements of the first row"
the cyclist
2018 年 5 月 10 日
Oops, there were actually a couple confusing typos in my post. I have edited to correct them. Thanks for pointing that out.
その他の回答 (1 件)
Ahamed Tuani
2017 年 11 月 13 日
Hi,
I have been looking into local search as well. Giannakis, I know its quite q while ago but have you figure out how to do it?
The cyclist and fellow members, I have a question..say the path is 1-31-9-2-10-1..I want to swap 9 and 2 so that the new path will be 1-31-2-9-10-1. How can I do this? Tried indexing (maybe a dumb way) i.e init_tour((1:2):(4):(3):6) to get the new tour but its not working. Any help will be greatly appreciated. Thanks.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!