Cumulative maximum of an array - MATLAB Cody - MATLAB Central

Problem 42633. Cumulative maximum of an array

Difficulty:Rate
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]'
See also cumin.

Solution Stats

17.01% Correct | 82.99% Incorrect
Last Solution submitted on Oct 08, 2025

Problem Comments

Solution Comments

Show comments
MATLAB EXPO 2025 Registration is Now Open! November 12 – 13, 2025
Registration is now open for MathWorks annual virtual event MATLAB EXPO 2025...
0

Problem Recent Solvers38

Suggested Problems

More from this Author44

Community Treasure Hunt

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

Start Hunting!