Matlab:max函数

Matlab中max函数在矩阵中求函数大小的实例如下:

C = max(A)
返回一个数组各不同维中的最大元素。
如果A是一个向量,max(A)返回A中的最大元素。
如果A是一个矩阵,max(A)将A的每一列作为一个向量,返回一行向量包含了每一列的最大元素。
如果A是多为数组,max(A) treats the values along the first non-singleton dimension as vectors, returning the maximum value of each vector.

C = max(A,B)
返回一个和A和B同大小的数组,其中的元素是从A或B中取出的最大元素。

C = max(A,[],dim)
返回A中有dim指定的维数范围中的最大值。

[C,I] = max(...)
找到A中那些最大值的索引位置,将他们放在向量I中返回。如果这里有多个相同最大值时,返回的将是第一个的索引。

详细举例:

细说MATLAB中的MAX函数 
一:MAX函数的几种形式 
(1)max(a) (2)max(a,b) (3)max(a,[],dim) (4)[C,I]=max(a) (5)[C,I]=max(a,[],dim) 
二:举例说明函数意思 
(1)max(a) 
如果a是一个矩阵,比如a=[1,2,3;4,5,6],max(a)的意思就是找出矩阵每列的最大值, 本例中:max(a)=[4,5,6] 
(2)max(a,b) 
如果a和b都是大于1维的矩阵,那么要求a和b的行列的维数都要相等,函数的结果是比较a和b中每个元素的大小,比如: 
a=[1,2,3;4,5,6]      b=[4,5,6;7,8,3] max(a,b)=[4,5,6;7,8,6] 

另外,如果a和b中至少有一个是常数,也是可以的。

比如: a=[1,2,3;4,5,6]         b=3        c=5 
          max(a,b)=[3,3,3;4,5,6]  

          max(b,c)=5 

相信大家看了例子都明白了函数的意思了吧       
(3)max(a,[],dim) 
这个函数的意思是针对于2维矩阵的,dim是英文字母dimension的缩写,意思是维数。 当dim=1时,比较的a矩阵的行,也就是和max(a)的效果是一样的;当dim2时,比较的是a矩阵的行。下面举个例子: 
a=[1,2,3;4,5,6]       max(a)=max(a,[],1)=[4,5,6]    比较的第一行和第二行的值                    max(a,[],2)=[3,6]

 

(4)[C,I]=max(a) 
C表示的是矩阵a每列的最大值,I表示的是每个最大值对应的下标: 下面举例说明: 
还是刚才那个例子:a=[1,2,3;4,5,6]          [C,I]=max(a) 
结果显示的是C=[4,5,6]       I=[2,2,2]   返回的是最大值对应的行号。 
(5)[C,I]=max(a,[],dim) 
同理:如果dim=1时,其结果和[c,i]=max(a)是一样的。 当dim=2时,同样上面的矩阵a,我们运行一下: 
[c,i]=max(a,[],2)     结果是:c=[3,6]   i=[3,3]    i返回的是矩阵a的列号。

----------------------------------------------
max

Maximum elements of an array

Syntax

C = max(A)
C = max(A,B)
C = max(A,[],dim)
[C,I] = max(...)

Description

C = max(A) returns the largest elements along different dimensions of an array. If A is a vector, max(A) returns the largest element in A. If A is a matrix, max(A) treats the columns of A as vectors, returning a row vector containing the maximum element from each column. If A is a multidimensional array, max(A) treats the values along the first non-singleton dimension as vectors, returning the maximum value of each vector.

C = max(A,B) returns an array the same size as A and B with the largest elements taken from A or B.

C = max(A,[],dim) returns the largest elements along the dimension of A specified by scalar dim. For example, max(A,[],1) produces the maximum values along the first dimension (the rows) of A.

[C,I] = max(...) finds the indices of the maximum values of A, and returns them in output vector I. If there are several identical maximum values, the index of the first one found is returned.

Remarks

For complex input A, max returns the complex number with the largest complex modulus (magnitude), computed with max(abs(A)), and ignores the phase angle, angle(A). The max function ignores NaNs.

See Also

isnan, mean, median, min, sort

转载于:https://www.cnblogs.com/realkate1/p/4836352.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值