I want to replace certain values in matrix/vector to -1, but can't seem to be able to.
x = [1 5 6; 2 4 3; 3 4 2; 4 2 1];
z = x(:,1) == 4 % get result I want
z =
0
0
0
1
changem(z,-1,0) % changem doesn't work
ans =
1
1
1
1
same if I make array in changem
changem(z,[-1 1],[0 1])
ans =
1
1
1
1
This also doesn't work
z(1) = -1
z =
1
0
0
1
Why can't I manipulate the vector to get the following values
ans =
-1
-1
-1
1
This approach works, but an answer to the previous question would be great, thanks.
z = x(:,1) ~= 4;
z = z * -1;
z = changem(z,1,0)
ans =
-1
-1
-1
1