## Loren on the Art of MATLABTurn ideas into MATLAB

Note

Loren on the Art of MATLAB has been archived and will not be updated.

# Another Possible Surprise – Ignored NaN Values

Ever have some data that might have some NaN values? And you start doing computations with these data, expecting |NaN|s to propagate... Only to find later, that the |NaN|s only went so far. Here's what's going on, for better or worse.

### NaNs Play Different Roles

I know of 3 typical uses of NaN values:

• to represent missing data
• result of computational ambiguity (e.g., 0/0)
• graphics directive to separate line segments in a single vector of point values

### Some MATLAB Functions Ignore NaN Values

There are several MATLAB functions that ignore NaN valuess, including

min, max, any, and all Here are a few little examples in action.

any([0 nan])
all([0 nan])
all([1 nan])
any([1 nan])
ans =
0
ans =
0
ans =
1
ans =
1


There are also a bunch of functions in Statistics Toolbox that ignore |NaN|s, including these:

nanmean, nanmin, nanmax, nancov, nanstd, nansum, nanvar, nanmedian

### Why Ignore NaNs?

The reason min, max, any and all ignore NaN values is for the the graphics case - where line segments in a line are separated by NaN, and finding the min and max values is useful for setting axis limits.

### How Do You Use NaNs?

Have you found the tools you need to work with your data containing NaN values? Do you need to work around them or do you embrace their presence? Let me know here.

Published with MATLAB® 7.13

### 댓글

댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.