Convert zeros to NAN

I have a matrix (N rows and M columns). It consists of integer values. I want to convert all the zero values from rows 1:N and columns 3:M to NaN. Is there any way to do so.
Thanks, Nancy

 Respuesta aceptada

Sean de Wolski
Sean de Wolski el 14 de Jun. de 2011

0 votos

One of many ways
idx = ~A;
idx(:,1:2) = false;
A(idx) = nan;

3 comentarios

Nancy
Nancy el 14 de Jun. de 2011
Thanks Sean. It works.
In your commands, step two ignores the values in columns one and two. Am I correct?
Sean de Wolski
Sean de Wolski el 14 de Jun. de 2011
Yes. It sets any value that was a zero value (the ~ (not) command) in the first definition to be false so that it doesn't show up in the nan assignment.
Nancy
Nancy el 14 de Jun. de 2011
Thanks. :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 14 de Jun. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by