MATLAB: How to swap this matrix

matlab 2012b swapping

i have this column of matrix
Z= 2
4
1
7
9
how to swap this 1 and 2

Best Answer

Z([1,2]) = Z([2,1]);
ADD
Z = [2
4
2
1
7
9
1
1]; % new case
a = [1, 2]; % replacement value
[l,ii] = ismember(Z,a);
Z(l) = a(3-ii(l));
Related Question