swap the values in matrix

4 Ansichten (letzte 30 Tage)
Anusha
Anusha am 24 Jan. 2014
Beantwortet: Neel Shah am 1 Nov. 2019
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 Kommentar
Raihan Ahmed
Raihan Ahmed am 22 Aug. 2015
Easy Method to do this is swapping Using index
b=[2:7]; b=b([2,1,3:end]);
this will give you the result :)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

ES
ES am 24 Jan. 2014
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;

Weitere Antworten (1)

Neel Shah
Neel Shah am 1 Nov. 2019
how to swap element in the 3*3 matrix
like a(2,1)=a(4,3)
a(4,3)=a(2,1)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by