Getting a mean of only the numbers

4 vues (au cours des 30 derniers jours)
Evelyn
Evelyn le 9 Oct 2014
Commenté : Evelyn le 9 Oct 2014
I have a dataset and I want the mean value of the numbers. There are a lot of NaN-values in there and I want to ignore those (the code
mean(data)
now gives 'NaN' as answer) How do I do this?

Réponse acceptée

Mischa Kim
Mischa Kim le 9 Oct 2014
Evelyn, use
mean(data(~isnan(data)))
  1 commentaire
Evelyn
Evelyn le 9 Oct 2014
Thank you so much!

Connectez-vous pour commenter.

Plus de réponses (1)

Thorsten
Thorsten le 9 Oct 2014
Use nanmean
  1 commentaire
Mischa Kim
Mischa Kim le 9 Oct 2014
That's another option. You need to have access to the Statistics Toolbox though.

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by