Quantcast
Channel: MATLAB Central Newsreader - tag:"mean"
Viewing all articles
Browse latest Browse all 26

Re: how to calculate mean2 with matrices containing NaNs

$
0
0
"Evan" wrote in message <ef2d052.-1@webx.raydaftYaTP>...
> I simply just want to calculate the mean of a m by n matrix (usually
> you would just use mean2). However the matrices conatin NaNs, there
> is a nanmean for 1D vectors but no nanmean2. How can i get around
> this?
>
> Thank you very much in advance for any help
>
> Evan.

There's a surprisingly easy way! Since nanmean takes the mean of each column and then puts those means into an array, do nanmean multiple times until you have the desired number of values.

For example,
      avg = nanmean(nanmean(nanmean(my_array)));

Viewing all articles
Browse latest Browse all 26

Trending Articles