Find values and replace them with NaN, add total number of NaN values.
128 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello! So within 3 different columns of data which I have defined as:
mintemp = b(:,4)
maxtemp = b(:,5)
avgtemp = b(:,6)
I want to take each individual row (1 column at a time) and find the -9999 values which are NaN values and replace them with 'NaN' so that when I calculate the average of one it doesn't skew the actual value, or find a way to calculate the average only using positive integers in Matlab if there is this function. Additionally, I would like to be able to keep a count of the total number of -9999 (NaN) values in that column so that I know how many missing values I have in the calculated average.
n=length(source_files);
for j= 1:n
mintemp = b(:,4)
NaN = -9999
ff= find(mintemp==NaN);
%This is about as far as I've got so far
f=ff+1
Any suggestions are appreciated! Thanks for your help everyone!
0 commentaires
Réponse acceptée
Dan Seal
le 17 Juil 2013
To replace all -9999 values with NaN, you can do:
mintemp(mintemp == -9999) = NaN;
If you have Statistics Toolbox, you can then use NANMEAN:
nanmean(mintemp)
If you don't have Statistics Toolbox, you can take the mean of the values that are not NaN:
mean(mintemp(~isnan(mintemp)))
If you don't want to replace things with NaN, and want to compute the average for only positive numbers, you can do this all in one command:
mean(mintemp(mintemp>0))
4 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur NaNs dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!