MATLAB: Hi .. if I have column A= [1 ;1;1;2;2;2;3;3;3] , how can I change the values that equals to 1 to be 3 and instantly change the values that equals 3 to 1.

matrix manipulation

the expected output is [3;3;3;2;2;2;1;1;1]

Best Answer

A= [1 ;1;1;2;2;2;3;3;3]
% B =[3;3;3;2;2;2;1;1;1]
C = A
C(A==1) = 3 ;
C(A==3) = 1 ;