主要内容

min

阵列的最小元素

描述

example

M= min(A)returns the minimum elements of an array.

  • 如果Ais a vector, thenmin(A)returns the minimum ofA

  • 如果A是矩阵,然后min(A)是一个行矢量,包含每列的最小值A

  • 如果A是一个多维数组,然后min(A)operates along the first dimension ofAwhose size does not equal1,将元素视为向量。这个维度的大小变成1尽管所有其他维度的尺寸保持不变。如果A是一个空数阵列,具有第一维0, thenmin(A)returns an empty array with the same size asA

example

M= min(A,[],dim)returns the minimum element along dimensiondim。例如,如果A是矩阵,然后最小值(一个[],2)is a column vector containing the minimum value of each row.

example

M= min(A,[],nanflag)指定包括还是省略NaNvalues in the calculation. For example,最小值(一个[],'includenan')includes allNaNvalues inAwhile最小值(一个[],'omitnan')ignores them.

M= min(A,[],dim,nanflag)还指定使用时要运行的维度nanflag选项。

example

[M,I] = min(___)还将索引返回到操作维度,对应于Afor any of the previous syntaxes.

example

M= min(A,[],'all')finds the minimum over all elements ofA。This syntax is valid for MATLAB®versions R2018b and later.

example

M= min(A,[],Vecdim)计算矢量中指定的尺寸的最小值Vecdim。例如,如果A是矩阵,然后最小值(一个[],[1 2])computes the minimum over all elements inA, since every element of a matrix is contained in the array slice defined by dimensions 1 and 2.

M= min(A,[],'all',nanflag)computes the minimum over all elements ofA什么时候using thenanflag选项。

M= min(A,[],Vecdim,nanflag)specifies multiple dimensions to operate along when using thenanflag选项。

[M,I] = min(A,[],'all',___)将线性索引返回到Athat corresponds to the minimum value inA指定时'all'

example

[M,I] = min(A,[],___,'linear')将线性索引返回到Athat corresponds to the minimum value inA

example

C= min(A,B)returns an array with the smallest elements taken fromAorB

C= min(A,B,nanflag)also specifies how to treatNaNvalues.

___= min(___,'ComparisonMethod',方法)可选地指定如何比较任何先前语法的元素。例如,对于向量A = [-1 2 -9], the syntaxmin([],“ComparisonMethod”、“abs”)compares the elements ofAaccording to their absolute values and returns-1

例子

collapse all

Create a vector and compute its smallest element.

A = [23 42 37 15 52]; M = min(A)
M = 15

Create a complex vector and compute its smallest element, that is, the element with the smallest magnitude.

A = [-2+2i 4+i -1-3i]; min(A)
ANS = -2.0000 + 2.0000i

Create a matrix and compute the smallest element in each column.

a = [2 8 4;7 3 9]
A =2×32 8 4 7 3 9
M = min(A)
M =1×32 3 4

Create a matrix and compute the smallest element in each row.

A = [1.7 1.2 1.5; 1.3 1.6 1.99]
A =2×31.7000 1.2000 1.5000 1.3000 1.6000 1.9900
m = min(a,[],,2)
M =2×11.2000 1.3000

Create a vector and compute its minimum, excludingNaNvalues.

a = [1.77 -0.005 3.98 -2.95 Nan 0.34 Nan 0.19];m = min(a,[],,'omitnan')
M = -2.9500

min(A)将艾尔so produce this result since'omitnan'is the default option.

Use the'includenan'flag to returnNaN

m = min(a,[],,'includenan')
m = nan

Create a matrixAand compute the smallest elements in each column as well as the row indices ofAin which they appear.

A = [1 9 -2; 8 4 -5]
A =2×31 9 -2 8 4 -5
[M,I] = min(A)
M =1×31 4 -5
I =1×31 22

Create a 3-D array and compute the minimum over 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]; M1 = min(A,[],[1 2])
M1 = M1(:,:,1) = -2 M1(:,:,2) = -5 M1(:,:,3) = -3

Starting in R2018b, to compute the minimum over all dimensions of an array, you can either specify each dimension in the vector dimension argument, or use the'all'选项。

M2 = min(A,[],[1 2 3])
M2 = -5
Mall = min(A,[],'all')
购物中心= -5

Create a matrixAand return the minimum value of each row in the matrixM。Use the'linear'option to also return the linear indicesIsuch thatM = A(I)

a = [1 2 3;4 5 6]
A =2×31 23 4 5 6
[M,I] = min(A,[],2,'linear')
M =2×11 - 4
I =2×11 2
minvals =A(I)
minvals =2×11 - 4

Create a matrix and return the smallest value between each of its elements compared to a scalar.

A = [1 7 3; 6 2 9]
A =2×31 7 3 6 2 9
B = 5; C = min(A,B)
C =2×31 5 3 5 2 5

Input Arguments

collapse all

输入数组, specified as a scalar, vector, matrix, or multidimensional array.

  • 如果Ais complex, thenmin(A)returns the complex number with the smallest magnitude. If magnitudes are equal, thenmin(A)returns the value with the smallest magnitude and the smallest phase angle.

  • 如果A是标量min(A)returnsA

  • 如果Ais a 0-by-0 empty array, thenmin(A)is as well.

如果Ahas type分类, then it must be ordinal.

Complex Number Support:Yes

方面to operate along, specified as a positive integer scalar. If you do not specify the dimension, then the default is the first array dimension of size greater than 1.

方面dimindicates the dimension whose length reduces to1。这尺寸(M,昏暗)is1, while the sizes of all other dimensions remain the same, unlesssize(A,dim)is0。如果size(A,dim)is0, then最小值(一个dim)returns an empty array with the same size asA

Consider anm-经过-n输入矩阵,A:

  • 最小值(一个[],1)computes the minimum of the elements in each column ofAand returns a1-经过-nrow vector.

    最小值(一个[],1) column-wise operation

  • 最小值(一个[],2)computes the minimum of the elements in each row ofAand returns anm-经过-1column vector.

    最小值(一个[],2) row-wise operation

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。这n最小值(一个[],[1 2])returns a 1-by-1-by-3 array whose elements are the minimums computed over each page ofA

Mapping of a 2-by-3-by-3 input array to a 1-by-1-by-3 output array

Additional input array, specified as a scalar, vector, matrix, or multidimensional array. InputsAandBmust either be the same size or have sizes that are compatible (for example,A是一个M-经过-N矩阵和Bis a scalar or1-经过-Nrow vector). For more information, see兼容数组大小的基本操作

  • AandB除非一个是双倍的。In that case, the data type of the other array can besingle,duration, or any integer type.

  • 如果AandBare ordinal分类arrays, they must have the same sets of categories with the same order.

Complex Number Support:Yes

NaNcondition, specified as one of these values:

  • 'omitnan'- 忽略所有NaNvalues in the input. If all elements areNaN, thenminreturns the first one.

  • 'includenan'— Include theNaN计算输入中的值。

Fordatetimearrays, you can also use'omitnat'or'includenat'to omit and includeNaTvalues, respectively.

For分类arrays, you can also use``省略定义''or“包含定义”to omit and include undefined values, respectively.

数据类型:char

数字输入的比较方法,指定为以下值之一:

  • 'auto'— For a numeric input arrayA, compare elements by真实(A)什么时候Ais real, and byABS(A)什么时候Ais complex.

  • '真实的'— For a numeric input arrayA, compare elements by真实(A)什么时候Ais real or complex. IfAhas elements with equal real parts, then useimag(A)to break ties.

  • 'abs'— For a numeric input arrayA, compare elements byABS(A)什么时候Ais real or complex. IfA具有相等大小的元素,然后使用angle(A)在间隔(-π,π)中打破领带。

输出参数

collapse all

Minimum values, returned as a scalar, vector, matrix, or multidimensional array.尺寸(M,昏暗)is1,而所有其他维度的大小与相应维度的大小相匹配A, 除非size(A,dim)is0。如果size(A,dim)is0, thenM是一个empty array with the same size asA

Index, returned as a scalar, vector, matrix, or multidimensional array.I与第一个输出相同。

什么时候'linear'is not specified,Iis the index into the operating dimension. When'linear'is specified,I包含线性索引A对应于最小值。

如果the smallest element occurs more than once, thenIcontains the index to the first occurrence of the value.

Minimum elements fromAorB, returned as a scalar, vector, matrix, or multidimensional array. The size ofCis determined by implicit expansion of the dimensions ofAandB。有关更多信息,请参阅兼容数组大小的基本操作

数据类型C取决于数据类型AandB:

  • 如果AandBare the same data type, thenCmatches the data type ofAandB

  • 如果是AorBissingle, thenCissingle

  • 如果是AorB是一个integer data type with the other a scalar双倍的, thenCassumes the integer data type.

Extended Capabilities

Version History

Introduced before R2006a