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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM