Cody

# Problem 42633. Cumulative maximum of an array

Solution 2151982

Submitted on 6 Mar 2020 by Stephen
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
filetext = fileread('cumax.m'); assert(isempty(strfind(filetext,'cummin'))) assert(isempty(strfind(filetext,'cummax'))) assert(isempty(strfind(filetext,'feval')))

2   Pass
x = randi(100); assert(isequal(cumax(x),cummax(x))) assert(isequal(cumax(x,1),cummax(x,1))) assert(isequal(cumax(x,2),cummax(x,2))) assert(isequal(cumax(x,1,'reverse'),cummax(x,1,'reverse'))) assert(isequal(cumax(x,2,'reverse'),cummax(x,2,'reverse'))) assert(isequal(cumax(x,'reverse'),cummax(x,'reverse')))

3   Pass
x = randi(100,randi([2 100]),1); assert(isequal(cumax(x),cummax(x))) assert(isequal(cumax(x,1),cummax(x,1))) assert(isequal(cumax(x,2),cummax(x,2))) assert(isequal(cumax(x,1,'reverse'),cummax(x,1,'reverse'))) assert(isequal(cumax(x,2,'reverse'),cummax(x,2,'reverse'))) assert(isequal(cumax(x,'reverse'),cummax(x,'reverse')))

4   Pass
x = randi(100,1,randi([2 100])); assert(isequal(cumax(x),cummax(x))) assert(isequal(cumax(x,1),cummax(x,1))) assert(isequal(cumax(x,2),cummax(x,2))) assert(isequal(cumax(x,1,'reverse'),cummax(x,1,'reverse'))) assert(isequal(cumax(x,2,'reverse'),cummax(x,2,'reverse'))) assert(isequal(cumax(x,'reverse'),cummax(x,'reverse')))

5   Pass
x = magic(10); assert(isequal(cumax(x),cummax(x))) assert(isequal(cumax(x,1),cummax(x,1))) assert(isequal(cumax(x,2),cummax(x,2))) assert(isequal(cumax(x,1,'reverse'),cummax(x,1,'reverse'))) assert(isequal(cumax(x,2,'reverse'),cummax(x,2,'reverse'))) assert(isequal(cumax(x,'reverse'),cummax(x,'reverse')))

6   Pass
x = []; assert(isequal(cumax(x),cummax(x))) assert(isequal(cumax(x,1),cummax(x,1))) assert(isequal(cumax(x,2),cummax(x,2))) assert(isequal(cumax(x,1,'reverse'),cummax(x,1,'reverse'))) assert(isequal(cumax(x,2,'reverse'),cummax(x,2,'reverse'))) assert(isequal(cumax(x,'reverse'),cummax(x,'reverse')))

### Community Treasure Hunt

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

Start Hunting!