Creating a loop for finding max value from a specified range

조회 수: 9 (최근 30일)
Jamie Mcwilliam
Jamie Mcwilliam 2017년 2월 24일
댓글: Jamie Mcwilliam 2017년 2월 24일
Hi all,
I have a vector with 8352 rows and I want to find the max value from each consecutive 288 rows, e.g 1:288, 289:577 etc. So I should end up with 29 max values
I am struggling with making a for loop with this
The vector size will change of course depending on the dataset I am using so need to account for this when reusing the loop
Thanks

채택된 답변

Jan
Jan 2017년 2월 24일
편집: Jan 2017년 2월 24일
x = rand(8352, 1);
x = reshape(x, 288, []);
y = max(x, [], 1);
And if the length is not a multiple of the window size:
Win = 288;
Len = size(x, 1);
LenP = Len - mod(Len, Win);
x = reshape(x(1:LenP), 288, []);
y = max(x, [], 1);
yRest = max(x(LenP:Len), [], 1);
  댓글 수: 5
Adam
Adam 2017년 2월 24일
편집: Adam 2017년 2월 24일
doc max
would tell you that the 2nd output argument gives you this:
[y,idx] = max(...);
Jamie Mcwilliam
Jamie Mcwilliam 2017년 2월 24일
Hi adam, yep I did use this but because the vector is reshaped the corresponding index does not match my time vector (8352x1)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by