フィルターのクリア

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

1 回表示 (過去 30 日間)
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.

採用された回答

Quad
Quad 2020 年 5 月 22 日
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
  2 件のコメント
Quad
Quad 2020 年 5 月 22 日
You may also be able to do something like this as well which is more concise.
Edu Utrabo Carazo
Edu Utrabo Carazo 2020 年 5 月 22 日
That worked just fine. Thank you so much.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Preprocessing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by