フィルターのクリア

Find max values for each year

5 ビュー (過去 30 日間)
Danilo M
Danilo M 2018 年 12 月 21 日
コメント済み: Mahtab Moalemi 2020 年 4 月 17 日
I have a time series matrix with hourly rain data like this:
[year month day hour minute secont rain]
rain = [2008 1 12 8 0 0
2008 1 12 9 0 0
2008 1 12 10 0 0
2008 1 12 11 0 0
2008 1 12 12 0 0.2
2008 1 12 13 0 0.2
2008 1 12 14 0 1
2008 1 12 15 0 1.6
2008 1 12 16 0 2.2
2008 1 12 17 0 1.6
2008 1 12 18 0 0.8
2008 1 12 19 0 1.6
2008 1 12 20 0 0.8
2008 1 12 21 0 0.6
2008 1 12 22 0 0.6
2008 1 12 23 0 0.8
2008 1 13 0 0 0.2
2008 1 13 1 0 1];
And I need to find the max value of rain(:,7) for each year, resulting in a matrix like
max = [2008 43.2
2009 41.4
2010 30.4
2011 36.6
2012 38.0];
How can I do this on MatLab?

採用された回答

Star Strider
Star Strider 2018 年 12 月 21 日
Your ‘rain’ array does not exactly match the header information you posted for it, since there are only 6 columns.
This fills in the ‘seconds’ column with a vector of zeros, then does what you requested:
rain = [2008 1 12 8 0 0
2008 1 12 9 0 0
2008 1 12 10 0 0
2008 1 12 11 0 0
2008 1 12 12 0 0.2
2008 1 12 13 0 0.2
2008 1 12 14 0 1
2008 1 12 15 0 1.6
2008 1 12 16 0 2.2
2008 1 12 17 0 1.6
2008 1 12 18 0 0.8
2008 1 12 19 0 1.6
2008 1 12 20 0 0.8
2008 1 12 21 0 0.6
2008 1 12 22 0 0.6
2008 1 12 23 0 0.8
2008 1 13 0 0 0.2
2008 1 13 1 0 1];
Times = datetime([rain(:,1:5) zeros(size(rain,1),1)]); % Create ‘datetime’ Array
TData = timetable(Times, rain(:,6)); % Convert To ‘timetable’
YrMean = retime(TData, 'yearly', 'max'); % Yearly Maximum
Max = [YrMean.Times.Year YrMean.Var1]
producing (with the posted data):
Max =
2008 2.2
Also, don’t name it ‘max’, since that overshadows the MATLAB max function. I capitalised it here to prevent that (MATLAB is case-sensitive).
  3 件のコメント
Star Strider
Star Strider 2020 年 4 月 16 日
Mahtab Moalemi —
Your Comment does not directly relate to this thread.
Please post this as a new Question, then delete your Comment.
Mahtab Moalemi
Mahtab Moalemi 2020 年 4 月 17 日
I have done that too! My question had the exact same title just the format was different. So it is actually related anyway.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by