Problem 42633. Cumulative maximum of an array
Find the cumulative maximum of an array without using the built-in function cummax (and a few others). Your function should act identically to cummax, allowing the same inputs.
Examples
If X = [0 4 3
6 5 2]
cumax(X,1) is [0 4 3 and cumax(X,2) is [0 4 4
6 5 3] 6 6 6]
cumax(X,1,'reverse') is [6 5 3 and cumax(X,2,'reverse') is [4 4 3
6 5 2] 6 5 2]
Also,
cumax([8 9 1 10 6 1 3 6 10 10]) returns [8 9 9 10 10 10 10 10 10 10]
cumax([8 9 1 10 6 1 3 6 10 10]') returns [8 9 9 10 10 10 10 10 10 10]'
Solution Stats
Problem Comments
-
3 Comments
Jean-Marie Sainthillier
on 7 Jul 2022
There is a problem is the first test.
Remove the assert(isempty(strfind(filetext,'max'))) because the name of the function cumax contains the string max.
Thank you.
Christian Schröder
on 7 Oct 2022
@Matthew, could you be so kind and fix the first test? As it is, it is impossible to solve this problem since the function name "cumax" itself contains the string "max".
This also makes it impossible to obtain the Matrix Manipulation III badge.
Dyuman Joshi
on 9 Oct 2022
The test suite has been updated temporarily.
Solution Comments
Show commentsGroup

Easy Sequences Volume II
- 10 Problems
- 5 Finishers
- Easy Sequences 13: Average Speed of Spaceship
- Easy Sequences 16: Volume of Embedded Octahedron
- Easy Sequences 18: Set Bits of Triple Summations
- Easy Sequences 21: Combinatorial Summations
- Easy Sequences 23: Hat Guessing Game!
- Easy Sequences 24: Number of Coprime Lattice Points
- Easy Sequences 25: Product of Series
- Easy Sequences 31: N-N's Sequence
- Easy Sequences 27: Product of Radicals of Integers
- Easy Sequences 28: Sum of Radicals of Integers
Problem Recent Solvers36
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!