LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to get the second high index from array max and min

Solved!
Go to solution

Hi,

 

I need help to find the second high index for the data array, how can i do it??

 

Attach with the vi snippet.

 

Thanks and regards,

Simon

0 Kudos
Message 1 of 19
(10,158 Views)
How about using Array Max and Min to get the highest value and its index.  Then use that index to delete that element from the array, then get use Array Max and Min again to get the highest.  If you want the index of that one as it was in the original array, you could compare the index to the one that was deleted and add 1 to the index in the event the original highest came before the 2nd highest.
0 Kudos
Message 2 of 19
(10,156 Views)

Hi,

Thanks for your suggestion here.

Somehow, if the highest 1 at last index & second highest at 2 last, then the second highest index not correct...(refer to attachment)

 

Thanks and regards,

Simon

0 Kudos
Message 3 of 19
(10,133 Views)

You didn't completely follow Raven's Fan advice. You would add 1 if the second highest index after the deletion is greater than or equal to the index of the highest value. If the index is less then you don't add anything.

 

Aside: are you assuming that each value in the array is unique? 

Message 4 of 19
(10,121 Views)
Solution
Accepted by topic author simon76

You forgot to do the comparison to see where the 2nd highest index fell relative to the highest.

 

You add 1 only if the 2nd highest comes after the highest.  You just added 1 regardless of position.

 

Message Edited by Ravens Fan on 05-05-2010 11:42 PM
Message 5 of 19
(10,120 Views)

Hi guys,

 

Thanks for your helps here.

Maybe i still in sleeping mode & miss out so important line. Smiley Surprised

Fyi, the data array is come out from the magnitude of power spectrum, so believe should be unique..

 

Thanks once again.

 

regards,

Simon

0 Kudos
Message 6 of 19
(10,111 Views)

simon76 wrote:

 

Fyi, the data array is come out from the magnitude of power spectrum, so believe should be unique..


Even so, it's quite possible that you'd get the same values for two or more elements, so that may be something you may want to consider handling. For example, if you get two elements that are both the highest value then the first Array Max and Min will find the first one. Once you delete it, calling Array Max and Min again will find the second instance of that same value, rather than the actual next highest.

Message 7 of 19
(10,104 Views)

Just an other way to do the same thing, quite simple an giving you also the index of the third, forth, and so on...

 

p.s. consider also the option of using a peak detection VI....

0 Kudos
Message 8 of 19
(10,043 Views)

hello 

 

can you please upload your vi?

0 Kudos
Message 9 of 19
(7,353 Views)

Angela93 a écrit :

hello 

 

can you please upload your vi?


Did you realized this is a 7 years old thread? It takes less than 2 minutes to replicate the code have you tried?

 

Note that there is a simpler way to do this using Sort Array_ogtk.vi from the OpenG toolkit but for large array the original method is probably more memory efficient.

 

Using OpenG.png

 

Ben64

Message 10 of 19
(7,344 Views)