[TOC]

cummax

Cumulative maximum

Usage

m = cummax(A)

m = cummax(A, dim)

m = cummax(A, option)

m = cummax(A, dim, option)

m = cummax(A, option1, option2)

m = cummax(A, dim, option1, option2)

OptionMeaningDefault
'forward'The cumulative maxima are obtained in the forward direction.Default for cumsum, cumprod, cummin, cummax
'reverse'The cumulative maxima are obtained in the reverse direction.Not default for cumsum, cumprod, cummin and cummax
'includenan'Include NaN in the calculationDefault for cumsum, cumprod
'omitnan'Omit NaN in the calculationDefault for cummax, cummin

Examples

Input
% Matrix of size [3,4]
A = reshape(1:12,3,4)
% Cumulative maxima
m = cummax(A)
Output
A =
 1.000   4.000   7.000   10.00
 2.000   5.000   8.000   11.00
 3.000   6.000   9.000   12.00

m =
 1.000   4.000   7.000   10.00
 2.000   5.000   8.000   11.00
 3.000   6.000   9.000   12.00
Input
% Matrix of size [3,4]
A = reshape(1:12,3,4)
% Cumulative maxima along 2nd dimension
m = cummax(A,2)
Output
A =
 1.000   4.000   7.000   10.00
 2.000   5.000   8.000   11.00
 3.000   6.000   9.000   12.00

m =
 1.000   4.000   7.000   10.00
 2.000   5.000   8.000   11.00
 3.000   6.000   9.000   12.00
Input
a = [1:5 nan 6]

% Default options
disp('Omit nan, forward')
cummax(a)

% Include nan, forward direction
disp('Include nan, forward.')
cummax(a, 'includenan')

% Omit nan, forward direction
disp('Omit nan, forward')
cummax(a, 'omitnan')

% Omit nan, forward direction
disp('Omit nan, forward')
cummax(a, 'forward')

% Omit nan, reverse direction
disp('Omit nan, reverse')
cummax(a, 'reverse')
Output
a = 
 1.0000   2.0000   3.0000   4.0000   5.0000   NaN      6.0000

Omit nan, forward

ans = 
 1.0000   2.0000   3.0000   4.0000   5.0000   5.0000   6.0000

Include nan, forward.

ans = 
 1.0000   2.0000   3.0000   4.0000   5.0000   NaN      NaN   

Omit nan, forward

ans = 
 1.0000   2.0000   3.0000   4.0000   5.0000   5.0000   6.0000

Omit nan, forward

ans = 
 1.0000   2.0000   3.0000   4.0000   5.0000   5.0000   6.0000

Omit nan, reverse

ans = 
 6.0000   6.0000   6.0000   6.0000   6.0000   6.0000   6.0000