Find values and replace them with NaN, add total number of NaN values.
131 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Dan Seal
2013-7-17
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!