How to take monthly flow data and obtain annual max flow values
    4 次查看(过去 30 天)
  
       显示 更早的评论
    
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 个评论
回答(2 个)
  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 :)
0 个评论
  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.
0 个评论
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

