5.0

5.0 | 11 ratings Rate this file 96 downloads (last 30 days) File Size: 7.63 KB File ID: #6837

NaN Suite

by Jan Gläscher

 

31 Jan 2005 (Updated 05 May 2008)

No BSD License  

Descriptive Statistics for N-D matrices ignoring NaNs.

Download Now | Watch this File

File Information
Description

The collection of functions in the NaN Suite enhances the functionality of the original 'nan'-functions in the Statistics Toolbox for N-D matrices. In addition, the new function nansem.m calculates the standard error of the mean ignoring NaNs.

The NaN Suite functions are used similar to the original functions (e.g. mean, std, var), that is they take a matrix as the first input, and the dimension along which the operation should be computed as the second input. For example, nanmean(A,4) calculates the mean of A along the 4th dimension of A ignoring NaNs.

MATLAB release MATLAB 6.5 (R13)
Zip File Content  
Other Files nansuite/nanmax.m,
nansuite/nanmean.m,
nansuite/nanmedian.m,
nansuite/nanmin.m,
nansuite/nansem.m,
nansuite/nanstd.m,
nansuite/nansum.m,
nansuite/nanvar.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (13)
24 Feb 2005 Julie Golomb

so useful -- thank you!

19 Mar 2005 Can Ozan Tan

pretty handy

31 May 2005 Daphne Weihs

Thanks!
This happened to be just what I needed.

08 Aug 2005 Rudolf von Steiger  
04 Aug 2006 dgfgf ddf

thanks a lot

12 Sep 2007 Uri Merhav

Great minds think alike, I see. I was just about to write out this code myself when I realized someone out there must also be using nan as a non-measurement, and want it ignored while computing average and standard deviation.

Good job.

03 Feb 2008 Santosh Verma

nice

05 May 2008 anony mouse

genius!

07 May 2008 Pieter Kuppens

Isn't life as simple as this:
nanmean(a) = mean(a(find(~isnan(a))))

10 Jul 2008 David Redish

Thank you for fixing this. We have been bitten regularly by Mathworks' strange decision to define nanxyz(all-nans) as 0, which propogates nans incorrectly. This suite has helped us tremendously.

05 Aug 2008 C D

This is a great suite of functions. I did notice the max/min toolbox functions in M7 filtered NaN's from the calculations. However, the other functions did not. So, that's where the NaN suite came in handy.

12 Jan 2009 miguel Ampudia

is there any function to do quintiles ignoring NaN? Thanks!

09 Oct 2009 Andrei Terebilo

Little bug here (otherwise great, thanks):

>> nanmedian([0 0 0 0 0 1])
ans =
   NaN

Just modify line 71:
i = find(y==0);
to
i = find(s==0);

Please login to add a comment or rating.
Updates
13 Jun 2005

bug fix in nansum.m

30 Jul 2007

bug fix in nanmedian. The function now returns NaN for an entire vector of NaNs.

05 May 2008

included an additional function nanvar.m which computes the variance for N-D matrices. It is very similar to nanstd.m without taking the square root.

Tag Activity for this File
Tag Applied By Date/Time
statistics Jan Gläscher 22 Oct 2008 07:40:27
probability Jan Gläscher 22 Oct 2008 07:40:27
nan Jan Gläscher 22 Oct 2008 07:40:27
mean Jan Gläscher 22 Oct 2008 07:40:27
std Jan Gläscher 22 Oct 2008 07:40:27
median Jan Gläscher 22 Oct 2008 07:40:27
var Jan Gläscher 22 Oct 2008 07:40:27
max Jan Gläscher 22 Oct 2008 07:40:27
min Jan Gläscher 22 Oct 2008 07:40:27
sum Jan Gläscher 22 Oct 2008 07:40:27
sem Jan Gläscher 22 Oct 2008 07:40:27
statistics Marco 19 Jun 2009 12:00:26
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com