Engee documentation

cummax

Cumulative maximum.

Library

EngeeDSP

Syntax

Function call

  • M = cummax(A) — returns the cumulative maximum elements of the array A.

    • If A — vector, then M — a vector of the same size and type containing the cumulative maxima of the vector A.

    • If A — the matrix, then M — a matrix of the same size and type containing cumulative maxima in each column of the matrix A.

    • If A — a multidimensional array, then M — an array of the same size and type containing cumulative maxima in the first dimension of the array A, the size of which is not equal to 1.

  • M = cummax(A,dim) — returns cumulative maxima by measurement dim. For example, if A — the matrix, then cummax(A,2) returns cumulative maxima across rows of the matrix A.

  • M = cummax(___,direction) — defines the direction for any of the previous syntax options. For example, cummax(A,2,"reverse") returns the cumulative maxima of the matrix A acting from the end to the beginning of the second dimension of the matrix A.

  • M = cummax(___,nanflag) — determines whether to exclude or include values NaN to the array A. For example, cummax(A,"includenan") takes into account the values NaN when calculating each maximum. By default cummax excludes values NaN.

Arguments

Input arguments

# A — input array

+ vector | the matrix | multidimensional array

Details

An input array specified as a vector, matrix, or multidimensional array. For complex elements, the function cummax compares their amplitudes. If the amplitudes are equal, cummax It also compares phase angles.

Типы данных

Float32, Float64, Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Bool

Support for complex numbers

Yes

# dim — the measurement for which the operation is performed

+ a positive integer scalar

Details

The dimension that the operation is performed on, specified as a positive integer scalar. If no dimension is specified, the first dimension of the array is used by default, the size of which is not equal to 1.

Consider a two-dimensional input array A:

  • cummax(A,1) works with consecutive elements in columns A and returns an array of the same size as A, with cumulative maxima in each column.

    cummax 1

  • cummax(A,2) works with consecutive elements in strings A and returns an array of the same size as A, with cumulative maxima in each row.

    cummax 2

cummax returns A if dim more than ndims(A).

# direction — cumulation direction

+ "forward" (by default) | "reverse"

Details

The direction of cumulation, set by one of the following values:

  • "forward" — work from 1 until the end of the working measurement;

  • "reverse" — end-to-end work 1 working measurement.

# nanflag — condition for missing value

+ "omitmissing" (by default) | "omitnan" | "includemissing" | "includenan"

Details

The condition for processing a missing value, set by one of the following values:

  • "omitmissing" or "omitnan" — ignore the values NaN in A when calculating cumulative maxima. If in A there are consecutive initial values NaN, then the corresponding elements in M They are also NaN. Values "omitmissing" and "omitnan" they behave the same way.

  • "includemissing" or "includenan" — enable values NaN in A when calculating cumulative maxima. Elements in M they become NaN As soon as in A the first value occurs NaN. Values "includemissing" and "includenan" they behave the same way.

Output arguments

# M — output array

+ vector | the matrix | multidimensional array

Details

The output array returned as a vector, matrix, or multidimensional array.

Examples

Cumulative maximum in the vector

Details

Let’s find the cumulative maximum of a vector of random integers of size 1 on 10.

import EngeeDSP.Functions: randi

v = randi([0,10],1,10)
1×10 Matrix{Float64}:
 3.0  9.0  6.0  6.0  10.0  3.0  8.0  8.0  4.0  6.0
import EngeeDSP.Functions: cummax

M = cummax(v)
1×10 Matrix{Float64}:
 3.0  9.0  6.0  6.0  10.0  3.0  8.0  8.0  4.0  6.0

Cumulative maximum in the columns of the matrix

Details

Let’s find the cumulative maximum of the columns of the matrix with the size 3×3.

A = [3 5 2; 1 6 3; 7 8 1]
3×3 Matrix{Int64}:
 3  5  2
 1  6  3
 7  8  1
import EngeeDSP.Functions: cummax

M = cummax(A)
3×3 Matrix{Float64}:
 3.0  5.0  2.0
 3.0  6.0  3.0
 7.0  8.0  3.0

Cumulative maximum in the rows of the matrix

Details

Let’s find the cumulative maximum of the rows of the matrix with the size 3×3.

A = [3 5 2; 1 6 3; 7 8 1]
3×3 Matrix{Int64}:
 3  5  2
 1  6  3
 7  8  1
import EngeeDSP.Functions: cummax

M = cummax(A, 2)
3×3 Matrix{Float64}:
 3.0  5.0  5.0
 1.0  6.0  6.0
 7.0  8.0  8.0

Reverse cumulative maximum

Details

Calculate the cumulative maximum in the third dimension of the array 2×2×3. We will indicate the direction "reverse" to calculate values from the end of the third dimension to the beginning.

A = cat([1 2; 3 4], [9 10; 11 12], [5 6; 7 8]; dims=3)
2×2×3 Array{Int64, 3}:
[:, :, 1] =
 1  2
 3  4

[:, :, 2] =
  9  10
 11  12

[:, :, 3] =
 5  6
 7  8
import EngeeDSP.Functions: cummax

M = cummax(A, 3, "reverse")
2×2×3 Array{Float64, 3}:
[:, :, 1] =
  9.0  10.0
 11.0  12.0

[:, :, 2] =
  9.0  10.0
 11.0  12.0

[:, :, 3] =
 5.0  6.0
 7.0  8.0

Cumulative maximum, including missing values

Details

Create a matrix containing the values NaN.

A = [3 5 NaN 4; 2 6 2 9; 1 3 0 NaN]
3×4 Matrix{Float64}:
 3.0  5.0  NaN      4.0
 2.0  6.0    2.0    9.0
 1.0  3.0    0.0  NaN

Calculate the cumulative maxima of the matrix, including the values NaN. For matrix columns containing any value NaN, the cumulative maximum values become equal NaN as soon as the first value is encountered NaN.

import EngeeDSP.Functions: cummax

M = cummax(A, "includenan")
3×4 Matrix{Float64}:
 3.0  5.0  NaN    4.0
 3.0  6.0  NaN    9.0
 3.0  6.0  NaN  NaN

Recommendations

Meaning "reverse" In many cumulative functions, it allows you to quickly perform directional calculations without having to flip or reflect the input array.