MATLAB: Swap the values in matrix

swapping

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]

Best Answer

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;