File Exchange

## NaN Suite

version 1.0.0.0 (7.63 KB) by Jan Gläscher

### Jan Gläscher (view profile)

Descriptive Statistics for N-D matrices ignoring NaNs.

Updated 05 May 2008

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.

Daniele Rocchetta

### Daniele Rocchetta (view profile)

Sorry for the scarce fantasy but could not find better words than those expressed by David Redish below:

"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."

Michael Demarmels

### Michael Demarmels (view profile)

woops someone already pointed this out. Ignore comment below

Hi I think there is a bug in nanmedian - i have a dataset (single row), DS, which contains no NaN values, but nanmedian(DS) = NaN. Matlab's normal median(DS)=0.
I think this is the problem - when the median actually equals zero, nanmedian thinks it =nan.

Anna

David

### David (view profile)

Just what I was looking for :-)
Haven't looked at why, but seems to run a little slowly.
Thanks :-)

Philip West

### Philip West (view profile)

The issue Binu found is also present in the nanvar function. where:

NaNsuite y = nanvar(x,dim,flag)
MATLAB y = nanvar(X,flag,dim)

William Thielicke

### William Thielicke (view profile)

Thanks for the contribution!

Binu

### Binu (view profile)

There is a bug in the order by which the Nan suite calls the 'dim' argument. This matters if you have replaced the matlab 'NaN' functions with the Nan suite.

NaNsuite y = nanstd(x,dim,flag)
MATLAB y = nanstd(X,flag,dim)
y = std(X,flag,dim)

Thomas Clark

### Thomas Clark (view profile)

Brilliant, thanks.

I'd give five stars if Andrei's bugfix were included. Will upgrade to 5* if the bug is fixed :)

Thul Dai

### Thul Dai (view profile)

Great package, thanks!

Also agreeing on the bug as well as fix found by Andrei Terebilo on 09 Oct 2009. Would be nice if the downloadable package could be fixed.

WP

### WP (view profile)

Thank you so much, this is useful!

Andrei Terebilo

### Andrei Terebilo (view profile)

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);

miguel Ampudia

### miguel Ampudia (view profile)

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

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.

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.

Pieter Kuppens

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

anony mouse

genius!

Santosh Verma

nice

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.

dgfgf ddf

thanks a lot

Rudolf von Steiger

Daphne Weihs

Thanks!
This happened to be just what I needed.

Can Ozan Tan

pretty handy

Julie Golomb

so useful -- thank you!

 5 May 2008 1.0.0.0 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. 30 Jul 2007 bug fix in nanmedian. The function now returns NaN for an entire vector of NaNs. 13 Jun 2005 bug fix in nansum.m
##### MATLAB Release Compatibility
Created with R13
Compatible with any release
##### Platform Compatibility
Windows macOS Linux