MATLAB: Quick way to change complex number into NaN

complex

If I have a matrix of A=[1 2 ; 2+i 3] I want to make it into A=[1 2; NaN 3] Is there anyway like using isnan function to do this? Thanx!

Best Answer

A(imag(A)~=0) = nan;