Borrar filtros
Borrar filtros

How to replace values with nan when there is a condition?

14 visualizaciones (últimos 30 días)
Elaheh
Elaheh el 18 de Abr. de 2018
Editada: Jan el 18 de Abr. de 2018
Hi. How could I add a condition to the following? I want NaN in accuracyC if its counterpart in RTc is nan but not when the value in accuracyC is 0. accuracyC and RTc are two matrices. I appreciate your help.
accuracyC(isnan(RTc)) = NaN;

Respuesta aceptada

Jan
Jan el 18 de Abr. de 2018
Editada: Jan el 18 de Abr. de 2018
 I want NaN in accuracyC if:
   its counterpart in RTc is nan
   but not when the value in accuracyC is 0.
index            = isnan(RTc) & ~(accuracyC == 0);
accuracyC(index) = NaN;

It is slightly more efficient to write x~=0 instead of ~(x==0).

Más respuestas (0)

Categorías

Más información sobre NaNs 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