フィルターのクリア

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

150 ビュー (過去 30 日間)
Theodore
Theodore 2013 年 7 月 17 日
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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by