From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

finding the 25th largest number in an array

How would I say find the 25th largest number in an array?

Or nth largest number?

Chris
Message 1 of 13
(4,205 Views)
n-th max value of an array...
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 2 of 13
(4,205 Views)
Hi Chris,

The attached V7.0 vi should do the trick.

Hope this helps,

Nick
0 Kudos
Message 3 of 13
(4,205 Views)
Hi Chris,

Sorry forgot to reverse array for Max value.

Nick
0 Kudos
Message 4 of 13
(4,205 Views)
Hello

You have got good answers. Now, I want to point one thing: should you have to eliminate duplicate values prior to calculate th nth value, take a look in www.openg.org. their toolkit has a vi to do that.

Hope it helps.

Alipio
---------------------------------------------------------
"Qod natura non dat, Salmantica non praestat"
---------------------------------------------------------
0 Kudos
Message 5 of 13
(4,205 Views)
hi,

Jus wanna to say that our example vi is of improvsed (I did it in 5 minutes as soon as I saw the posting), thus not able to provide best solution.

Please bear in mind that spoon-feed won't help. We are jus doing our best to help.

Thanks.
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 6 of 13
(4,205 Views)
Ok. I know everybody tries to help doing his best.
I only wanted to show a good source of labview code. I think OpenG people works hard and they will feel happy if can be of help for labview community.

Thanks.
---------------------------------------------------------
"Qod natura non dat, Salmantica non praestat"
---------------------------------------------------------
0 Kudos
Message 7 of 13
(4,205 Views)
I find most of these answers correct, but without previous knowledge of the size of the array, I would do things differently.

In the enclosed VI, a cluster is formed of all array values and their index. When the array is then sorted, the first cluster element is used as the first sort criterium, then the second cluster element. This allows a single array operation (Sorting) to take care of any searching, whilst the cluster retains the index of the original array.

Coupling this method with an unitialised shift register, you can also cache the sorted array to allow for more rapid processing if you require more than a single indexed value.

Another way to achieve this is (Assuming you`re seeking the 25 largest) to simply get the max and min at t
he very beginning, feed the array into a loop with a shift register, set the value at the index returned for max each run to the initial min value -1, and repeat another 24 times.

Regarding memory use and execution speed, I`m not sure if searching an array 25 times is quicker than a single sort or not (No new array is created), but both versions are viable.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 8 of 13
(4,205 Views)
Good evening!

Nuttin' to it, my friend. Look at the attached vi.


Eric
Eric P. Nichols
P.O. Box 56235
North Pole, AK 99705
0 Kudos
Message 9 of 13
(4,205 Views)
🙂
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 Kudos
Message 10 of 13
(4,205 Views)