MATLAB: How to replace values with nan when there is a condition

nan replacement

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;

Best Answer

 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).