Code covered by the BSD License  

Highlights from
Ignore NaN

5.0

5.0 | 2 ratings Rate this file 17 Downloads (last 30 days) File Size: 1.9 KB File ID: #15776
image thumbnail

Ignore NaN

by Matt G

 

01 Aug 2007 (Updated 30 Aug 2007)

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

| Watch this File

File Information
Description

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]

std(X)

ans =

       NaN 1.5275 NaN

>> ignoreNaN(X,@std)

ans =

         0 1.5275 2.1213

This function is designed to work on any size array.

MATLAB release MATLAB 7.3 (R2006b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
31 Aug 2010 Rehana

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

01 Dec 2010 Matt G

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

23 Mar 2011 Naresh Pai  
21 Oct 2011 Kathryn McCormick  
Please login to add a comment or rating.
Updates
15 Aug 2007

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

30 Aug 2007

correction for case of size(X,2)=1, and nargin==2

Tag Activity for this File
Tag Applied By Date/Time
matrices Matt G 22 Oct 2008 09:21:26
ignore Matt G 22 Oct 2008 09:21:26
nan Matt G 22 Oct 2008 09:21:26
missing Matt G 22 Oct 2008 09:21:26
data Matt G 22 Oct 2008 09:21:26
invalid Matt G 22 Oct 2008 09:21:26
matrix manipulation Matt G 22 Oct 2008 09:21:27

Contact us at files@mathworks.com