Median that ignores Nans

1 view (last 30 days)
Ger
Ger on 19 Jul 2011
Hello,
just wondering if anyone can help me with the Median function?
I have long-term rainfall data in a matrix of 306 stations by 149 years (as I have already chosen a month) with rainfall in millimetres or NaNs for no values. I previously have been able to get the mean value for all years for each station by using
z = nanmean(values) ;
Now I would like to get the median for a chosen column but my results keep coming up with the median being NaNs for most stations.
Is anyone able to help with this?
Thankyou
  1 Comment
Ger
Ger on 19 Jul 2011
i realise that what i actually need is nanmedian but it doesn't appear to be in my version of MATLAB R2011a.
Would anyone have that file to exchange?
thanks

Sign in to comment.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 19 Jul 2011
Out = arrayfun(@(i1)median(In(~isnan(In(:,i1)),i1)),1:size(In,2));
  1 Comment
Ger
Ger on 19 Jul 2011
thanks, that worked perfectly

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!