Problem with the mean function
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone,
I've got a little pb with the 'mean' function :
My matrix has a class 'double' on my workspace : <70080*1 double> I would like to do an average of those values :
moyenne = mean(refoulement(1:8760,1)) and the answer is NaN. The values are positives.
Do you have an idea ?
Thanks !
0 commentaires
Réponse acceptée
Kye Taylor
le 2 Mai 2012
Try this
meanWithoutNans = mean(refoulement(~isnan(refoulement)));
2 commentaires
Kye Taylor
le 2 Mai 2012
I interpret you question as, "How do I take the mean of rows in a matrix and avoid the nans?"
To do that, try
meanOfRowsWithoutNans = zeros(size(refoulement,1),1);
for i = 1:size(refoulement,1) % for each row
meanOfRowsWithoutNans(i) = ...
mean(refoulement(i,~isnan(refoulement(i,:))));
end
Plus de réponses (3)
Image Analyst
le 2 Mai 2012
What does this say:
hasNans = max(isnan(refoulement))
I want to see if there are any nan's in your original matrix.
0 commentaires
Sean de Wolski
le 2 Mai 2012
If you have the Stats Toolbox, take a peak at:
doc nanmean
Also this FEX submission:
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!