How do I find the maximum value of every 7 days

2 views (last 30 days)
Hello!
I have a matrix consisting of daily maxima water levels. For a project, i need to find the weekly maxima. To do so, I want to find the maximum values of every 7 rows. For example:
[year month day Waterlevel]
2000 1 1 94
2000 1 2 95
2000 1 3 98
2000 1 4 101
2000 1 5 103
2000 1 6 104
2000 1 7 105
2000 1 8 106
2000 1 9 106
2000 1 10 104
2000 1 11 102
2000 1 12 102
2000 1 13 101
2000 1 14 99
These are the first 14 rows of my matrix. So i want to find the maximum value of rows 1:7 and then 8:14, 15:21 and so on. Also, I wish to keep the days

Accepted Answer

KSSV
KSSV on 10 Jun 2020
d = (1:36)' ; % let this be number of days
z = rand(size(d)) ; % let this be your water level
% make d divisble by 7 for reshaping
n = length(d) + (7 - rem(length(d),7)) ;
n = n-length(d) ;
d = [d ; NaN(n,1)] ; % append NaN's if extra values are needed
z = [z ; NaN(n,1)] ; % append NaN's if extra values are needed
% reshape to 7 rows
d = reshape(d,7,[]) ;
z = reshape(z,7,[]) ;
iwant = max(z) ; % get maximum for each 7 days

More Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!