Re: Max value vector [message #15496] |
Wed, 26 May 1999 00:00  |
Amara Graps
Messages: 24 Registered: June 1996
|
Junior Member |
|
|
"Thomas C. Stubbings" wrote:
>
> What I would need is something like the MATLAB command max(i) where i is an
> array(n,m) and max(i) returns a vector containing the maximum value of each
> column. The IDL max command only returns a scalar containing the absolute
> maximum of the array.
>
> I even tried a big loop running through each column to find the max of each,
> but IDL doesnt accept loops with 64000 iterations
>
> What alternatives do I have?
>
> Thomas
Thomas,
Here is another alternative among your choices. I wrote this simple
function to mimic Matlab's min function. Just change the occurences of
"min" with "max" and you'll have what you are looking for.
Amara
------------------------------------------------------------ ---------------
FUNCTION WMMIN, array, ind
;+
;NAME:
; WMMIN
;
;PURPOSE:
; To find the minimum elements of an array or matrix. This
; function works the same way as Matlab's MIN: [y,ind]=min(array)
;
;CATEGORY:
; Math.
;CALLING SEQUENCE:
; Result = WMMIN(array, ind)
;
;INPUTS:
; Array: The data array.
;
;OUTPUTS:
; Result =
; WMMIN returns the lowest value of an array, or if the
array
; is a matrix, it returns the lowest value of each
*column* in
; the matrix.
; ind = the index of the lowest value(s).
;
;NOTES: IDL's array indices are one less than Matlab's.
;
;EXAMPLE:
; >array=[[1,3,2],[6,3,4],[9,1,0]]
; >print, array
; 1 3 2
; 6 3 4
; 9 1 0
; y= WMMIN(array, ind)
; >print, y
; 1 1 0
; >print, ind
; 0 2 2
;
;MODIFICATION HISTORY:
; Amara Graps, BAER, San Francisco, December 1994.
; Amara Graps, Multiplex Answers, Heidelberg, April 1999.
; Modified to handle "degenerate" matrices (0 length in one
dimen)
;-
array = REFORM(array) ;eliminates the "degenerate" dimension(s)
t = SIZE(array)
IF t(0) eq 1 THEN BEGIN
;1D array
minval = MIN(array)
ind = !c
ENDIF ELSE BEGIN
;Matrix
numcol = t(1) ;number of columns
numrow=t(2) ;number of rows
minval = FLTARR(numcol)
ind = FLTARR(numcol)
;Step through the cols, and find the mins of the columns
;(the way Matlab does it)
FOR i = 0L, numcol-1 DO BEGIN
tt = array(i,*)
minval(i) = MIN(tt)
ind(i) = !c
END ;i
ENDELSE
!c = 0
RETURN, minval
END
;*********************************************************** *************
--
************************************************************ ***
Amara Graps | Max-Planck-Institut fuer Kernphysik
Interplanetary Dust Group | Saupfercheckweg 1
+49-6221-516-543 | 69117 Heidelberg, GERMANY
Amara.Graps@mpi-hd.mpg.de * http://galileo.mpi-hd.mpg.de/~graps
************************************************************ ***
"Never fight an inanimate object." - P. J. O'Rourke
|
|
|