max

max(X) returns the maximum value of vector X.
  • [m, i] = max(X) returns the maximum value of vector X and its index
  • max(X,Y) returns maximum value by comparing X and Y element-wise
If X is a matrix:
  • max(X) returns a vector with the maximum element for each of X columns
  • max(X,[],2) returns a vector with the maximum element for each of X rows

Examples

>> X = [2 4 1 2]
max(X)#

	4
>> max(3,2)#

 3
>> max(3,2:5)#

            3            3            4            5
>> X = [2 4 1 2; 5 3 1 1]#

            2            4            1            2
            5            3            1            1


>> max(X)#

            5            4            1            2


>> max(X, [], 2)#

            4
            5


>> max(X, 2)#

            2            4            2            2
            5            3            2            2
>> X = [2 1 4 1; 8 4 3 5]
[M i] = max(X, [], 2)

[X:2x4 double]
[M:2x1 double]
[i:2x1 double]

>> M#

            4
            8


>> i#

            3
            1

Resources

See also

mean | median | min | sort