23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2 Data Types<br />

NaN<br />

<strong>MATLAB</strong> represents values that are not real or complex numbers with a<br />

special value called NaN, which stands for Not a Number. Expressions like 0/0<br />

and inf/inf result in NaN, as do any arithmetic operations involving a NaN.<br />

For example, the statement n/0, wheren is complex, returns NaN for the real<br />

part of the result:<br />

x = 7i/0<br />

x =<br />

NaN +<br />

Infi<br />

Use the isnan function to verify that the real part of x is NaN:<br />

isnan(real(x))<br />

ans =<br />

1<br />

<strong>MATLAB</strong> also provides a function called NaN that returns the IEEE arithmetic<br />

representation for NaN as a double scalar value:<br />

x = NaN;<br />

whos x<br />

Name Size Bytes Class<br />

x 1x1 8 double<br />

Logical Operations on NaN. Because two NaNs arenotequaltoeach<br />

other, logical operations involving NaN always return false, except for a test<br />

for inequality, (NaN ~= NaN):<br />

NaN > NaN<br />

ans =<br />

0<br />

NaN ~= NaN<br />

ans =<br />

1<br />

2-26

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!