Empty for loop matrix

Hi there, I'm trying to make a for loop matrix for 90th percentiles of winter rainfall data from a NetCDF file. The code that I have written produces an empty matrix.
fname=[diri fili_1];
fname=fname(~isspace(fname));
prate = single(ncread(fname,'pr'));
TIME=ncread(fname,'time');
TIME2 = double(TIME)/24 + datenum('1970-01-01 00:00:00');
TIME3=datestr(TIME2,0);
dates =datevec(TIME3);
months=dates(:,2);
select_month = dates(:,2)==1 | dates(:,2)==2 | dates(:,2)==12;
winter_precipitation = prate(select_month,:);
%Create a for loop for the graph
mat = winter_precipitation;
startyear = 1981:1999;
endyear = 1982:2000;
nyrs=length(startyear);
P=90;
pmat=zeros(nyrs,12);
for iyr = 1:nyrs
k=find(mat(:,1)>=startyear(iyr) & mat(:,1)<=endyear(iyr));
delmat=mat(k,:);
pmat(iyr,:)=prctile(delmat,P,1);
end

5 件のコメント

Jan
Jan 2020 年 12 月 14 日
Okay. What is your question? What do you expect? Which matrix is empty? What di you expect instead? Did you use the debugger to step throught your code line by line already?
Maya Lewis
Maya Lewis 2020 年 12 月 14 日
  • I want a matrix of the annual 90th percentiles values for nyrs
  • Each column are the results for a different ensemble of the climate model I'm looking at (12 ensembles)
Jan
Jan 2020 年 12 月 14 日
What do you observe exactly? You did not mention, what the problem is, except for "produces an empty matrix".
Maya Lewis
Maya Lewis 2020 年 12 月 14 日
So when I run the code, I want a matrix full of rainfall values, from pmat. What I get instead is NaN in every position.
Soryr I've been working on it so long I've forgotten nobody else knows what I'm doing ahah.
Jan
Jan 2020 年 12 月 14 日
I know this problem. Questions for clarifications are a standard step in solving problems :-)

サインインしてコメントする。

回答 (1 件)

Matt J
Matt J 2020 年 12 月 14 日

0 投票

I would rewrite the loop as follows,
for iyr = 1:nyrs
k= mat(:,1)>=startyear(iyr) & mat(:,1)<=endyear(iyr);
if ~any(k),
error 'No data satisifes the condition'
end
delmat=mat(k,:);
pmat(iyr,:)=prctile(delmat,P,1);
end

カテゴリ

ヘルプ センター および File ExchangeClimate Science and Analysis についてさらに検索

タグ

質問済み:

2020 年 12 月 14 日

コメント済み:

Jan
2020 年 12 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by