How do I find the maximum value of every 7 days

조회 수: 2 (최근 30일)
Michiel Smit
Michiel Smit 2020년 6월 10일
댓글: Michiel Smit 2020년 6월 11일
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

채택된 답변

KSSV
KSSV 2020년 6월 10일
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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by