How do I assign values of 0 or 1 to numbers greater or lesser than a value?
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (2)
Sean de Wolski
el 2 de Mayo de 2012
mgt37 = m > 37
where m is your matrix. You did not specify what you want to do if an element of m equals 37.
Walter Roberson
el 2 de Mayo de 2012
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;
1 comentario
Brandon
el 2 de Mayo de 2012
Categorías
Más información sobre NaNs en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!