swap the values in matrix

2 ビュー (過去 30 日間)
Anusha
Anusha 2014 年 1 月 24 日
回答済み: Neel Shah 2019 年 11 月 1 日
Hello,
I have a matrix
[2 3 4 5 6 7]
a=2
b=3
i want to swap two values
ans is
[3 2 4 5 6 7]
  1 件のコメント
Raihan Ahmed
Raihan Ahmed 2015 年 8 月 22 日
Easy Method to do this is swapping Using index
b=[2:7]; b=b([2,1,3:end]);
this will give you the result :)

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

採用された回答

ES
ES 2014 年 1 月 24 日
InMtx=[2 3 4 5 6 3 3 4 2];
a=2;
b=3;
Twos=InMtx==a;
Threes=InMtx==b;
InMtx(Twos)=b;
InMtx(Threes)=a;

その他の回答 (1 件)

Neel Shah
Neel Shah 2019 年 11 月 1 日
how to swap element in the 3*3 matrix
like a(2,1)=a(4,3)
a(4,3)=a(2,1)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by