How do I assign values of 0 or 1 to numbers greater or lesser than a value?

I have a matrix of 16X200 numbers and wanted to change the values below 37 to 0 and above 37 to 1. How would I do this?
Thank you

 Accepted Answer

More Answers (2)

mgt37 = m > 37
where m is your matrix. You did not specify what you want to do if an element of m equals 37.
NewMatrix = cast(YourMatrix > 37, class(YourMatrix));
NewMatrix(YourMatrix == 37) = 37;
The first line does the bulk of the work. The cast() and class() and second line are there because you want entries that are exactly 37 to remain unchanged.
You may wish to think about
NewMatrix = YourMatrix >= 37;

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!