# cummin

Cumulative minimum

### m = cummin(A)

• A is an array of any number of dimensions.
• The output argument m contains the cumulative minimums and has the same size as A.
• The cumulative minimums are obtained from vectors along the first non-singleton dimension of A.

Example 1: In the following, the first non-singleton dimension of A is the first dimension. The minimum operation is performed along the vertical direction. For instance, m(:,1) contains cumulative minimums of elements of A(:,1).

% Matrix of size [3,4]
A=reshape(1:12,3,4)
% Cumulative minimums
m=cummin(A)

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
1.000   4.000   7.000   10.00
1.000   4.000   7.000   10.00


### m = cummin(A, dim)

• dim should be a positive integer scalar, not equal to inf or nan.
• It obtains the cumulative minimums along the dim-th dimension of A.
• If size(A,dim) == 1 or dim > ndims(A), then m is the same as A.

Example 2: In the following, The minimum operation is performed along the horizontal direction (2nd dimension). For instance, m(1,:) contains cumulative minimums of elements of A(1,:).

% Matrix of size [3,4]
A=reshape(1:12,3,4)
% Cumulative minimums along 2nd dimension
m=cummin(A,2)

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   1.000   1.000   1.000
2.000   2.000   2.000   2.000
3.000   3.000   3.000   3.000


### m = cummin(A, option)

• option should be either 'reverse', 'forward', 'includenan' or 'omitnan'.
• These options control the operation direction, or whether or not NaN should be included in the operation.
• For details, see Tables 1 and 2 below.

Note

By default, cummin and cummax omit NaN, whereas cumsum and cumprod include NaN.

Example 3: Cumulative minimums of the same vector but with different options. Note that cummin by default omits NaN, therefore NaN elements in a is ignored when cummin is called for the first time below. In the second call of cummin, NaN is included in the comparison. Therefore, NaN appears in the output since comparison with NaN returns NaN.

a=[1:5 nan 6]
% Default options
cummin(a)
% Include nan, forward direction
cummin(a, 'includenan')
% Omit nan, forward direction
cummin(a, 'omitnan')
% Forward direction, include nan
cummin(a, 'forward')
% Reverse direction, include nan
cummin(a, 'reverse')

a =
1.000   2.000   3.000   4.000   5.000    nan   6.000

ans =
1.000   1.000   1.000   1.000   1.000   1.000   1.000

ans =
1.000   1.000   1.000   1.000   1.000    nan    nan

ans =
1.000   1.000   1.000   1.000   1.000   1.000   1.000

ans =
1.000   1.000   1.000   1.000   1.000   1.000   1.000

ans =
1.000   2.000   3.000   4.000   5.000   6.000   6.000


Table 1: Options for operation direction.

Option value Meaning Default
'forward' The cumulative minimums are obtained in the forward direction. YES
'reverse' The cumulative minimums are obtained in the reverse direction. NO

Table 2: Options for including or omitting NaN.

Option value Meaning Default
'omitnan' Omit NaN in the opeartion YES
'includenan' Include NaN in the operation NO

### m = cummin(A, dim, option)

• Same as m = cummin(A, dim) above, except that an option can be specified for controlling the operation direction or whether or not NaN should be included.
• See Tables 1 and 2 above for available options.

### m = cummin(A, option1, option2)

• Same as m = cummin(A, option) above, except that two options can be specified at the same time.
• option2 will overwrite option1 if they contradict each other.
• See Tables 1 and 2 above for available options.

### m = cummin(A, dim, option1, option2)

• Same as m = cummin(A, dim, option) above, except that two options can be specified at the same time.
• option2 will overwrite option1 if they contradict each other.
• See Tables 1 and 2 above for available options.