File Exchange

image thumbnail

Ignore NaN

version 1.0 (1.9 KB) by

returns the result of the function of an array ignoring NaN elements



View License

Occasionally I record missing data, invalid data or erroneous data as NaN. But if I have a array of data where the columns are different measurements and the rows are different measurement times the NaNs make it difficult to perform statistical operations on.

This Function will perform a function on the data (assuming the function is designed to operate on an array) but it will ignore any NaNs.

For example
X=[ 1 2 4;
1 5 NaN;
NaN 3 1]


ans =

NaN 1.5275 NaN

>> ignoreNaN(X,@std)

ans =

0 1.5275 2.1213

This function is designed to work on any size array.

Comments and Ratings (6)

Nolan Conaway

Is there a way to use this for functions that take two arguments? (i.e., dotprod (x,y))?


Andrey (view profile)

Excellent!!! Works like charm.

Naresh Pai

Matt G

Matt G (view profile)

There is an example in the description above. You may also want to review function handles


Rehana (view profile)

Plz tell me how to use this file in my code so that I can use "ignoreNaN" in my code?


This correction will return NaN if all element operated on are NaNs.

Also with the previous version if a vector of NaNs was on the outside dimension the correct result was not returned.

See Screenshot

MATLAB Release
MATLAB 7.3 (R2006b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today