Reference Guide > M–N Routines > MAX Function
  

MAX Function
Returns the value of the largest element in an input array.
enabled.
Usage
result = MAX(array[, max_subscript])
Input Parameters
array—The array to be searched.
max_subscript(optional) The subscript of the maximum element in array:
*If supplied, max_subscript is converted to a long integer containing the index of the largest element in array.
*If max_subscript is not supplied, the system variable !C is set to the index of the largest element in the array.
Returned Value
result—The value of the largest element in array. The result is given in the same data type as array. If the Dimension keyword is used, then the values of result, max_subscript, and Min will all have the structure of the input array, but with dimension n collapsed.
 
note
If array is complex then the returned value is the element of array with the maximum real part.
Keywords
Dimension—An integer (n 0) designating the dimension over which the maximum is taken.
Min—Used to specify a variable to hold the value of the minimum array element.
 
note
If you need to find both the minimum and maximum array values, use this keyword to avoid scanning the array twice with separate calls to MAX and MIN.
Example 1
x = [22, 40, 9, 12]
PRINT, MAX(x)
; PV-WAVE prints: 40
Example 2
x = [3, 4, 5, 6, 7, 8, 9]
maxval = MAX(x, maxindex, Min=minval)
PRINT, maxval
; PV-WAVE prints: 9
PRINT, maxindex
; PV-WAVE prints: 6
PRINT, minval
; PV-WAVE prints: 3
Example 3
a = [[1,1,3,2], [3,4,1,3], [3,0,1,0], [0,1,2,0]]
PM, a
; PV-WAVE prints: 
; 1       3       3       0
; 1       4       0       1
; 3       1       1       2
; 2       3       0       0
PM, MAX(a, Dimension=0)
; PV-WAVE prints: 3       4       3       2
PM, MAX(a, Dimension=1)
; PV-WAVE prints: 
; 3
; 4
; 3
; 3
 
a = INDGEN( 1, 2, 3, 4, 5 )
INFO, MAX(a, Dimension=2)
; PV-WAVE prints: <Expression>    INT       = Array(1, 2, 1, 4, 5)
See Also
!C, AVG, EXTREMA, MEDIAN, MIN, alibMinMax, alibMinMaxDim

Version 2017.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.