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

14 次查看(过去 30 天)
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;

采纳的回答

Jan
Jan 2018-4-18
编辑:Jan 2018-4-18
 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).

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 NaNs 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by