How to take monthly flow data and obtain annual max flow values

조회 수: 4 (최근 30일)
William Taylor
William Taylor 2019년 9월 26일
답변: Akira Agata 2019년 9월 26일
I have a data set with months (numbered from 1 to 12) in column 1 and monthly max flows in column 2. I would like to obtain the yearly maximum flows over the entire 81 year span (972 months) of this dataset. Essentially, for every 12 months (1-12) I would like to find a maximum and then I would like to compile these 81 flows (the month of max occurrence in a year does not matter to me). Any tips on how I might go about this?
1 36000
2 218000
3 24300
4 43200
5 8430
6 2230
7 535
8 205
9 110
10 100
11 4220
12 18100
1 6680
2 53600
3 27000
4 20100
5 2030
6 680
7 150
8 80
9 120
10 144
11 4500
12 7020

답변 (2개)

Ajay Kumar
Ajay Kumar 2019년 9월 26일
편집: Ajay Kumar 2019년 9월 26일
Your data being X,
data = X(:,2);
yearly_max = zeros(length(data)/12,1);
j=1;
for i=1:length(data)/12
yearly_max(i)=max(data((j:j+11),1));
j=j+12;
end
Here, I have neglected the first column in X (your matrix), as it is of no use.
Please accept the answer, if you got what you need. Thanks :)

Akira Agata
Akira Agata 2019년 9월 26일
Assuming your data was stored in 972-by-2 matrix yourData, following code can do your task.
year = repelem([1:81]',12,1);
yearlyMax = splitapply(@max,yourData(:,2),year);
By the way, if you will do some more analysis on your data, I would recommend creating datetime vector and storing your data as timetable variable.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by