cummax

Cumulative maximum: running largest value along an array.

Category: Data Import and Analysis > Descriptive Statistics

Syntax

M = cummax(A)

Running maximum along the first non-singleton dimension.

M = cummax(A, dim)

Along dimension dim.

Description

The result never decreases. It is useful for tracking a best-so-far value, a high-water mark, or drawdowns in a series (compare the data with its running maximum).

For a matrix, cummax(A) works down each column and cummax(A, 2) along each row.

Input arguments

A
Numeric array.
dim
Dimension to operate along.

Output arguments

M
Array of the same size as A; M(k) is the largest of the first k elements.

Example

Running maximum

x = [1 3 2 5 4];
cummax(x)
A = [1 5; 3 2; 4 9];
cummax(A, 2)
Output
ans = 1×5

     1     3     3     5     5
ans = 3×2

     1     5
     3     3
     4     9

See also

cummin cumsum max movmax