How do I know the number of days that the data exceeds a given treshold in a year?

1 Ansicht (letzte 30 Tage)
I have daily measured data for 50 years at 90 weather stations (including February 29 in leap years). I want to now how many days the data exceeds a given treshold at each station each year.
I tried to do a datetime variable and a timetable for each station like this but I do not know how to continue:
t1 = (datetime(1950,1,1):datetime(1999,12,31))' ;
for i = 1:90
TT = timetable(t1,temperature(:,i));
end
If I did not have February 29, I would know how to solve the problem with a reshape of the matrix. However, I do not know how to deal with my data since there will be years with 365 days and others with 366 and the reshape is not valid.
Thank you very much in advance.

Akzeptierte Antwort

Quad
Quad am 22 Mai 2020
Something like this should work fine. I made some fake data and some random threshold.
t1 = (datetime(1950,1,1):datetime(1999,12,31))' ;
temp = rand(length(t1),90); % Make fake temp data
threshold = 0.25; % some threshold
year = t1.Year; % pull the years from t1
dataYears = (1950:1999); % the possible years from the data
numExceeded = zeros(length(dataYears),90); % initialize matrix to hold the num exceeded per year per station
count = 1;
for n = 1:length(dataYears)
numExceeded(n,:) = sum(temp(dataYears(n)==year,:)>threshold); % sum number of exceeded values
end
T = array2table(numExceeded);
% Make table "pretty"
varNames = cell(1,90);
for n = 1:90
varNames{n} = sprintf('Station_%d',n);
end
rowNames = cell(1,length(dataYears));
for n = 1:length(dataYears)
rowNames{n} = sprintf('%d',dataYears(n));
end
T.Properties.VariableNames = varNames;
T.Properties.RowNames = rowNames;
display(T);
This does not use timetable, but instead makes the row names the year

Weitere Antworten (0)

Kategorien

Mehr zu Data Preprocessing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by