MATLAB Answers

0

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

Asked by William Taylor on 26 Sep 2019
Latest activity Answered by Akira Agata
on 26 Sep 2019
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

  0 Comments

Sign in to comment.

Products


Release

R2019b

2 Answers

Answer by Kumar
on 26 Sep 2019
Edited by Kumar
on 26 Sep 2019

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 :)

  0 Comments

Sign in to comment.


Answer by Akira Agata
on 26 Sep 2019

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.

  0 Comments

Sign in to comment.