Borrar filtros
Borrar filtros

How can I replace integer values in a array?

1 visualización (últimos 30 días)
Noman Abir
Noman Abir el 3 de En. de 2021
Respondida: Image Analyst el 3 de En. de 2021
I Have some values in a array like this.
A = -4
-4
-4
4
4
4
I want to convert all negative values to 0 and all positive values to 1.
How can I do that.??
Outcome should be :
B = 0
0
0
1
1
1

Respuestas (2)

Matt J
Matt J el 3 de En. de 2021
Editada: Matt J el 3 de En. de 2021
B=(sign(A)+1)/2
  1 comentario
William
William el 3 de En. de 2021
... but be aware that sign(0)=0, so B becomes 0.5 in this case.

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 3 de En. de 2021

Categorías

Más información sobre Numeric Types en Help Center y File Exchange.

Productos


Versión

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by