I am working on a project where I'm trying to find multi-day events where temperature exceeds the 90th percentile.
I'm using 61 years of data and trying to calculate the percentiles based on each month between June-August. In other words, using the prctile
function, I would like to calculate the 90th percentile for June, July, and August and compare each month's daily temperature values based on the 90th percentile value for that month.
Ultimately, I want the program to find strings of days (2-day, 3-day, 4-day, 5-day, etc.) where the temperature exceeds the 90th percentile value, based on that month's value.
Below is the code I have so far:
fprintf('Loading the data...\n')
load file_name.txt
year=file_name(:,1);
month=file_name(:,2);
day=file_name(:,3);
temax=file_name(:,6);
temin=file_name(:,9);
molen=[30 31 31];
for y=1:61
for m=6:8
for k=1:molen
g1=find(year==y+1950&month==m&day==k&temax>-99);
g2=find(year==y+1950&month==m&day==k&temin>-99);
end
temaxpct=prctile(temax(g1),90);
teminpct=prctile(temin(g2),90);
end
clear g*
end
exceedence=find(year&month&day&temax>=temaxpct&temin>=teminpct);
I don't know how to make the program calculate the 90th percentile for each month (instead of the whole 3-month range June-August).
Additionally, I don't know how to make the program find strings of days where the temperature exceeds the 90th percentile, especially, since 4-day events also include 3-day events and 2-day events.
I know there needs to be some if/else statements, but I'm not sure how to set it up.
Just from reading your question (without digging through the code), here are two pointers:
Hope this can get you on track.