I am trying to grab the max for each year in my dataset. The data is in one column, in order at a daily timestep.
How do I get the max from the first 365 rows, then from the next 365 rows?
I was thinking something like:
years=31;
for i=1:years
peak(i)=max(data(i:365*i,2))
end
but when i=2, the range should be from 366:730 and so forth.
The data matrix is 11322×7 double and I need column 2.
I thought about suggesting something like @Thilo’s answer, but that doesn’t take into account leap years (which appear to show up in your data, since 365*31=11315, which is less than 11322)
You might be able to gin up a complicated vectorized solution, but I’d be tempted to just manually keep track of the start and stop indices:
It’s probably not blazingly fast, but I doubt this is going to be a bottleneck either.