How to replace values in a matrix?

6 visualizaciones (últimos 30 días)
Molly Baltins
Molly Baltins el 21 de Sept. de 2015
Comentada: Star Strider el 22 de Sept. de 2015
Hello,
I am fairly new to MATLAB and I have a question. How do you replace a value in a matrix? So if I have a matrix A, where A=3,2,5,-6. How can I find, and replace all of the negative numbers with 0? So I want to end up with a matrix of 3,2,5,0.
Thank you!
Molly

Respuesta aceptada

Star Strider
Star Strider el 21 de Sept. de 2015
One way is to use ‘logical indexing’:
A = [3,2,5,-6];
A(A<0) = 0
A =
3 2 5 0

Más respuestas (1)

Molly Baltins
Molly Baltins el 21 de Sept. de 2015
Thank you! This has helped a lot!
  5 comentarios
Molly Baltins
Molly Baltins el 22 de Sept. de 2015
Perfect! That is exactly what u wanted! Thank you!
Star Strider
Star Strider el 22 de Sept. de 2015
Again, my pleasure!

Iniciar sesión para comentar.

Categorías

Más información sobre Text Analytics Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by