MATLAB: Complex number determination

complex numbersMATLAB

How can I check if a number is imaginary? I want to set an if function, that if a variable is an aimginary number then something will happen.

Best Answer

z - your number
out = imag(z) ~= 0;
if out = true, then z - complex number
OR
out = isreal(z)
if out = false, then z - complex number