Rolling max/min maximum and minimum
2 views (last 30 days)
Show older comments
This may have already been asked and aswered, but I couldn't find anything on Matlab Answers or Google. Is there a slick vectorized way to calculate a rolling maximum/minimum for a vector. So the maximum over the previous n values (inclusive of the current value). For indices i < n the value should either be the max of the values with indices 1:i or NaN, I can live with either. So for example:
x = [1, 3, 2, 7, 4, 3]; n = 2;
should give
rollingMax = [NaN, 3, 3, 7, 7, 4] or [1, 3, 3, 7, 7, 4]
0 Comments
Answers (3)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!