How can I refer to a specific item of an array?

Recommended Posts

I have two arrays, which are filled with values every time when a specific event happens. The first item of the first array corresponds to the first item of the other array, e.t.c...

I want to determine where the minimum value of the first array is, and pick the value of the corresponding item from the other array.

I guess I should use filter and min commands together, but I suppose there would be a simpler solution.
Maybe I could simply get the index of the minimum value and simply pick the same index from the other.

How can I do that?


Thank you in advance!

Share this post

Link to post
Share on other sites

The trick to that is to use the time portion of the array to store the index.  Let's assume the arrays are arr1 and arr2:

arr1 = insertTime(arr1,0,1)

Then, to get the index of the minimum, just do gettime() on that minimum:

private theMin = min(arr1)
private indexMin = getTime(theMin)

Now you can just index into arr2 using indexMin.

Min() and Max(), in addition to returning the appropriate value, stick the time of that value into the time portion of the result.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now