MATLAB: Elimination based on threshold

threshold

I have a matrix A = [0 1 4 2; 1 2 0 3; 0 1 1 0; 1 0 3 1]. How can i automatically set all pixels less than 3 to zero and pixels equal or greater than 3 to one.

Best Answer

Try this:
A = [0 1 4 2; 1 2 0 3; 0 1 1 0; 1 0 3 1]
A(A<3) = 0 % Must come first!
A(A>3) = 1
In the command widnow:
A =
0 0 1 0
0 0 0 3
0 0 0 0
0 0 3 0
Related Question