find minimum
Paul Gr
pauls_postbus at hotmail.com
Wed Jun 28 19:54:30 UTC 2006
hello colleen,
It is not very difficult to create those functions and add them to the user
script section. The only drawback is that you will have to create separate
functions for each data type you use as base type for the array's. For
unspecified data types (variants) you could use the following function:
function FindMinIndex( a() ) as integer
dim i as integer
dim iMinIndex as integer
dim vMinValue
iMinIndex = LBound(a)
vMinValue = a(iMinIndex)
for i = LBound(a)+1 to UBound(a)
if a(i)<vMinValue then
iMinIndex = i
vMinValue = a(i)
end if
next
FindMinIndex = iMinIndex
end function
Add this to the user script section and you will be able to test it with the
following piece of example script:
Dim t(0 to 2)
t(0) = 0
t(1) = -3
t(2) = 5
Dim i as integer
i = FindMinIndex(t)
MsgBox "value at " & i & " has value " & t(i)
You can easy modify this function to match the data type of the array you
would like to use. As an example this is the function for an array of
integers:
function FindMinIndex_integer( a() as integer ) as integer
dim i as integer
dim iMinIndex as integer
dim vMinValue as integer
iMinIndex = LBound(a)
vMinValue = a(iMinIndex)
for i = LBound(a)+1 to UBound(a)
if a(i)<vMinValue then
iMinIndex = i
vMinValue = a(i)
end if
next
FindMinIndex_integer = iMinIndex
end function
And test it with the following:
Dim t(0 to 2) as integer
t(0) = 0
t(1) = -3
t(2) = -5
Dim i as integer
i = FindMinIndex_integer(t)
MsgBox "value at " & i & " has value " & t(i)
Hope this helps,
Paul Groot
Vrije Universiteit Amsterdam
> At 20:01 2006-06-28, Colleen Parks wrote:
>
> Hi,
>
> I've got an array to which I've assigned a list of random numbers
>(e.g., Array(0) = random(0,100)). I need to find which element/array
>position has the lowest value without sorting the array (position in the
>array is important for another variable later on). I've spent a good
>amount of time searching to figure out what the code is to find the minimum
>value of a list of variables, but haven't found anything yet. There is no
>obvious documentation of a general "find min" and "find max" function
>outside of the summation object. (Note that a summation object won't help
>because it will return the minimum of a set of values, but will not, as far
>as I can tell, indicate which variable (or observation) the minimum value
>is linked to). There's got to be a find min/max ability in there
>somewhere! Can anyone point me in the right direction?
>
> Thanks!
> Colleen
>
>
> ---------------------------------------
> Colleen Parks, Ph.D.
> Psychology Department
> University of California
> One Shields Ave.
> Davis, CA 95616
>
> cmparks at ucdavis.edu
> 530.754.9439
> Fredrik Ullén
> Associate Professor
> Stockholm Brain Institute
> Dept Woman and Child Health
> Neuropediatric Research Unit (ALB, Q2:07)
> Karolinska Institutet
> SE-171 76 Stockholm
> Sweden
> personal web page www.fredrikullen.com
>
More information about the Eprime
mailing list