bounds - Minimum and maximum values of an array - MATLAB (original) (raw)
Minimum and maximum values of an array
Syntax
Description
[[minA](#bvkopy8-S),[maxA](#bvkopy8-L)] = bounds([A](#bvkopy8-A))
returns the minimum value minA
and maximum valuemaxA
in an array. minA
is equivalent tomin(A)
and maxA
is equivalent tomax(A)
.
[[minA](#bvkopy8-S),[maxA](#bvkopy8-L)] = bounds([A](#bvkopy8-A),`"all"`)
computes the minimum and maximum values over all elements ofA
.
[[minA](#bvkopy8-S),[maxA](#bvkopy8-L)] = bounds([A](#bvkopy8-A),[dim](#bvkopy8-dim))
operates along the dimension dim
of A
. For example, if A
is a matrix, then bounds(A,2)
returns column vectors minA
and maxA
containing the minimum and maximum values in each row.
[[minA](#bvkopy8-S),[maxA](#bvkopy8-L)] = bounds([A](#bvkopy8-A),[vecdim](#mw%5Fee43a8e2-7f43-461d-8e9d-ecb41223121b))
computes the minimum and maximum values based on the dimensions specified in the vector vecdim
. For example, if A
is a matrix, then bounds(A,[1 2])
returns the minimum and maximum values over all elements in A
, since every element of a matrix is contained in the array slice defined by dimensions 1 and 2.
[[minA](#bvkopy8-S),[maxA](#bvkopy8-L)] = bounds(___,[missingflag](#mw%5F270e225f-13b5-49d6-a280-0e7d2547c661))
specifies whether to omit or include missing values in A
for any of the previous syntaxes. For example, bounds(A,"missingflag")
includes all missing values when computing the minimum and maximum values. By default, bounds
omits missing values.
Examples
Simultaneously compute the minimum and maximum values of a vector.
A = [2 4 -1 10 6 3 0 -16]; [minA,maxA] = bounds(A)
Compute the minimum and maximum values in each row of a matrix.
A = 4×4
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
[minA,maxA] = bounds(A,2)
Create a 3-D array and compute the minimum and maximum values in each page of data (rows and columns).
A(:,:,1) = [2 4; -2 1]; A(:,:,2) = [9 13; -5 7]; A(:,:,3) = [4 4; 8 -3]; [minA1,maxA1] = bounds(A,[1 2]); minA1
minA1 = minA1(:,:,1) =
-2
minA1(:,:,2) =
-5
minA1(:,:,3) =
-3
maxA1 = maxA1(:,:,1) =
4
maxA1(:,:,2) =
13
maxA1(:,:,3) =
8
To compute the bounds over all dimensions of an array, you can either specify each dimension in the vector dimension argument or use the "all"
option.
[minA2,maxA2] = bounds(A,[1 2 3])
[minAall,maxAall] = bounds(A,"all")
Create a matrix containing NaN
values.
A = [2 NaN 6 -5; 0 3 NaN 9]
A = 2×4
2 NaN 6 -5
0 3 NaN 9
Compute the minimum and maximum values of the matrix, including NaN
values. For matrix columns that contain any NaN
value, the minimum and maximum are NaN
.
[minA,maxA] = bounds(A,"includenan")
Input Arguments
Input array, specified as a vector, matrix, multidimensional array, table, or timetable.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
| categorical
| datetime
| duration
| table
| timetable
Complex Number Support: Yes
Dimension to operate along, specified as a positive integer scalar. If you do not specify the dimension, then the default is the first array dimension whose size does not equal 1.
Consider an m
-by-n
input matrix,A
:
bounds(A,1)
computes the minimum and maximum values in each column ofA
and returns two1
-by-n
row vectors.bounds(A,2)
computes the minimum and maximum values in each row ofA
and returns twom
-by-1
column vectors.
Vector of dimensions, specified as a vector of positive integers. Each element represents a dimension of the input array. The lengths of the output in the specified operating dimensions are 1, while the others remain the same.
Consider a 2-by-3-by-3 input array, A
. Then[minA,maxA] = bounds(A,[1 2])
returns a 1-by-1-by-3 array for both minA
and maxA
. The elements of minA
and maxA
are the minimum and maximum values in the corresponding page ofA
, respectively.
Missing value condition, specified as one of the values in this table.
Value | Input Data Type | Description |
---|---|---|
"omitmissing" | All supported data types | Ignore missing values in the input array, and compute the minimum and maximum over fewer points. If all elements in the operating dimension are missing, then the corresponding elements in minA andmaxA are missing. |
"omitnan" | double, single,duration | |
"omitnat" | datetime | |
"omitundefined" | categorical | |
"includemissing" | All supported data types | Include missing values in the input array when computing the minimum and maximum. If any element in the operating dimension is missing, then the corresponding elements in minA andmaxA are missing. |
"includenan" | double, single,duration | |
"includenat" | datetime | |
"includeundefined" | categorical |
Output Arguments
Minimum value, returned as a vector, matrix, multidimensional array, or table.
Maximum value, specified as a vector, matrix, multidimensional array, or table.
Extended Capabilities
Thebounds
function fully supports tall arrays. For more information, see Tall Arrays.
The bounds
function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced in R2017a
Omit or include missing values in the input array when computing the minimum and maximum by using the "omitmissing"
or"includemissing"
options. Previously,"omitnan"
, "includenan"
,"omitnat"
, "includenat"
,"omitundefined"
, and "includeundefined"
specified a missing value condition that was specific to the data type of the input array.
The bounds
function can calculate on all variables within a table or timetable without indexing to access those variables. All variables must have data types that support the calculation. For more information, see Direct Calculations on Tables and Timetables.
Operate on multiple dimensions of the input array at a time. Specify a vector of operating dimensions, or specify the "all"
option to operate on all array dimensions.