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
"Charlotte Chaze" <cchaze@udel.edu> wrote in message <o5be4n$ahb$1@newscl01ah.mathworks.com>...

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

That is not a wise advise. Run this to see why you have to be careful about take the average of the average where the number of invalid elements are dispersed.

A=nan(100,100);
A(1,:)=1;
A(:,1)=1e6;

% Replace with nanmean with you have stats tbx

mean(mean(A,'omitnan'),'omitnan')
mean(mean(A','omitnan'),'omitnan')
mean(A(:),'omitnan')

Viewing all articles
Browse latest Browse all 26

Trending Articles