how to calcuate mean with NaN
Afficher commentaires plus anciens
Dear Friend,
There are two matrixs with the same size, there are some NaNs in each matrix. I want to calculate the mean of corresponding datapoints, which might contain NaN. for example, A(1,2)=NaN, B(1,2)=3, I need the average of the sum of 3+NaN divided by the effective number of data points, here is 1 since A(1,2) is NaN, to be 3. If A(2,2)=2,B(2,2)=5, I need the average to be (2+5)divided by 2, which equals 3.5 since neither A(2,2) and B(2,2) contains NaN. Is there a way to achieve this goal without using a for loop? thanks
Réponse acceptée
Plus de réponses (2)
Shashank Prasanna
le 12 Sep 2013
0 votes
You can use the NANMEAN function part of the Statistics Tbx:
Catégories
En savoir plus sur Univariate Discrete Distributions dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!