필터 지우기
필터 지우기

Find values and replace them with NaN, add total number of NaN values.

조회 수: 150 (최근 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!

채택된 답변

Dan Seal
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
Dan Seal
Dan Seal 2013년 7월 17일
Feel free to accept this answer if it solved your problem :)
Theodore
Theodore 2013년 7월 17일
Sorry had to refresh to see the comment on getting a count for my -9999/NaN values, which is the only other thing I was waiting on. Worked like a charm! Thanks a ton again!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by