Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to skip/ignore NaN's when calculating means

Subject: How to skip/ignore NaN's when calculating means

From: Kirk

Date: 4 May, 2010 16:45:19

Message: 1 of 4

I am running multiple iterations of a simulation process and then outputting means from all iterations with a simple call like this:

% Calculate means from Monte Carlo runs
tmax_mean=mean(tmax,2);

Every so often... one time in a thousand or so, the random combination of parameters results in NaN output. Which of course, results in NaN means.
 
I am looking for a MATLABish approach to calculate the mean of the variable tmax, but skip the NaNs.

Thanks in advance

Subject: How to skip/ignore NaN's when calculating means

From: Sean

Date: 4 May, 2010 17:02:06

Message: 2 of 4

"Kirk" <kwythers.nospam@umn.edu> wrote in message <hrpiuv$1nq$1@fred.mathworks.com>...
> I am running multiple iterations of a simulation process and then outputting means from all iterations with a simple call like this:
>
> % Calculate means from Monte Carlo runs
> tmax_mean=mean(tmax,2);
>
> Every so often... one time in a thousand or so, the random combination of parameters results in NaN output. Which of course, results in NaN means.
>
> I am looking for a MATLABish approach to calculate the mean of the variable tmax, but skip the NaNs.
>
> Thanks in advance

>>help nanmean

Subject: How to skip/ignore NaN's when calculating means

From: us

Date: 4 May, 2010 17:45:09

Message: 3 of 4

"Kirk" <kwythers.nospam@umn.edu> wrote in message <hrpiuv$1nq$1@fred.mathworks.com>...
> I am running multiple iterations of a simulation process and then outputting means from all iterations with a simple call like this:
>
> % Calculate means from Monte Carlo runs
> tmax_mean=mean(tmax,2);
>
> Every so often... one time in a thousand or so, the random combination of parameters results in NaN output. Which of course, results in NaN means.
>
> I am looking for a MATLABish approach to calculate the mean of the variable tmax, but skip the NaNs.
>
> Thanks in advance

a hint:
- if(f) you own the stats tbx

     help nanmean; % <- and siblings...

us

Subject: How to skip/ignore NaN's when calculating means

From: Kirk

Date: 4 May, 2010 17:51:04

Message: 4 of 4

> >>help nanmean

Wow. That's nice!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us