Main Content

bounds

Smallest and largest elements

Description

example

[S,L] = bounds(A)returns the smallest elementSand largest elementLof an array.S相当于min(A)andL相当于max(A).

example

[S,L] = bounds(A,'all')computes the smallest and largest values over all elements ofA. This syntax is valid for MATLAB®versions R2018b and later.

example

[S,L] = bounds(A,dim)operates along the dimensiondimofA. For example, ifAis a matrix, thenbounds(A,2)returns column vectorsSandLcontaining the smallest and largest elements of each row.

example

[S,L] = bounds(A,vecdim)computes the smallest and largest values based on the dimensions specified in the vectorvecdim. For example, ifAis a matrix, thenbounds(A,[1 2])returns the smallest and largest values over all elements inA, since every element of a matrix is contained in the array slice defined by dimensions 1 and 2.

example

[S,L] = bounds(___,nanflag)specifies whether to include or omitNaNvalues when determining the smallest and largest elements.bounds(A,'omitnan')ignoresNaNvalues. If any element ofAisNaN, thenbounds(A,'includenan')returnsNaNfor bothSandL. The default behavior is'omitnan'.

Examples

collapse all

Simultaneously compute the smallest and largest values of a vector.

A = [2 4 -1 10 6 3 0 -16]; [S,L] = bounds(A)
S = -16
L = 10

Compute the smallest and largest elements of each row of a matrix.

A = magic(4)
A =4×416 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
[S、L] =马林nds(A,2)
S =4×12 5 6 1
L =4×116 11 12 15

Create a 3-D array and compute the smallest and largest 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]; [S1,L1] = bounds(A,[1 2]); S1
S1 = S1(:,:,1) = -2 S1(:,:,2) = -5 S1(:,:,3) = -3
L1
L1 = L1(:,:,1) = 4 L1(:,:,2) = 13 L1(:,:,3) = 8

Starting in R2018b, 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.

[S2,L2] = bounds(A,[1 2 3])
S2 = -5
L2 = 13
[Sall,Lall] = bounds(A,'all')
Sall = -5
Lall = 13

Include and ignore NaN elements of a vector when computing its smallest and largest values.

IgnoreNaNvalues when computing the largest and smallest values of a vector, which is the default.

一个=[2南6 5 0南10];[S、L] =马林nds(A)
S = -5
L = 10

Use the'includenan'option to includeNaNvalues, which causesboundsto returnNaNfor both the smallest and largest values ofA.

[S、L] =马林nds(A,'includenan')
S = NaN
L = NaN

Input Arguments

collapse all

Input array, specified as a vector, matrix, or multidimensional array.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|logical|categorical|datetime|duration
Complex Number Support:Yes

Dimension to operate along, specified as a positive integer scalar. If no value is specified, then the default is the first array dimension whose size does not equal 1.

Consider a matrixA.

  • bounds(A,1)computes the smallest and largest values of each column.

  • bounds(A,2)computes the smallest and largest values of each row.

Data Types:double|single|int8|int16|int32|int64|uint8|uint16|uint32|uint64

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[S、L] =马林nds(A,[1 2])returns a 1-by-1-by-3 array for bothSandL. The elements ofSandLare the smallest and largest values in the corresponding page ofA, respectively.

Data Types:double|single|int8|int16|int32|int64|uint8|uint16|uint32|uint64

NaNcondition, specified as one of these values:

  • 'omitnan'— Ignore allNaNvalues in the input. If the input contains onlyNaNvalues, thenboundsreturnsNaNfor bothSandL.

  • 'includenan'— IncludeNaNvalues. If any element of the input isNaN, thenboundsreturnsNaNfor bothSandL.

Output Arguments

collapse all

Smallest element, specified as a vector, matrix, or multidimensional array.

Largest element, specified as a vector, matrix, or multidimensional array.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

See Also

|

Introduced in R2017a