Sort or Compare 20 Values

javaninger

Member
Join Date
Mar 2010
Location
mo
Posts
10
I currently have an array with 20 counters. I would like to find the top (highest .ACC value) five of the total 20 and use that information.

I need to compare all 20 counters.
Take largest 5.

Counter0.ACC = 2
Counter1.ACC = 4
Counter2.ACC = 3
Counter3.ACC = 7
Counter4.ACC = 10
Counter5.ACC = 2
so on....

(I could do this as string or some other method)
TopFive0 = Counter4
TopFive1 = Counter3
TopFive2 = Counter1
so on....


Any thoughts? I am thinking the data could be stored in a UDT.

Thanks,
John
 
I currently have an array with 20 counters. I would like to find the top (highest .ACC value) five of the total 20 and use that information.

I need to compare all 20 counters.
Take largest 5.

Counter0.ACC = 2
Counter1.ACC = 4
Counter2.ACC = 3
Counter3.ACC = 7
Counter4.ACC = 10
Counter5.ACC = 2
so on....

(I could do this as string or some other method)
TopFive0 = Counter4
TopFive1 = Counter3
TopFive2 = Counter1
so on....


Any thoughts? I am thinking the data could be stored in a UDT.

Thanks,
John

Are you looking to store just the "values" of the largest 5 or the "indentity" of the largest 5.
 
So if I wanted to sort the counters, I would have to copy their value to another array like SortedCounters[20]? Would this array just be an array of INT's then?
 
It would be a DINT array.

Use an FAL instruction to copy the counter[falcontrol.pos].acc to the array[falcontrol.pos] and then sort the array.
 
If it is simply just values you are concerned about, first make your counter an array.

Counter[0].ACC, Counter[1].ACC, etc.

Then make another 5 DINT array for your values
TopFive[0], TopFive[1], etc

What happens if several counters tie for fifth place?
 

Similar Topics

I have an unusual task with a PanelView Plus 7 (running v11 firmware) and a CompactLogix. The customer wants to place a version number string in...
Replies
3
Views
613
Hello all, I was looking into different sorting techniques and actually found a bubble/insertion sort sample code file on Rockwell's site. Only...
Replies
20
Views
5,239
Hello all, I am attempting to sort a selection list via 'part-selection' buttons. Ex. a certain type of model is selected, I only want to have...
Replies
5
Views
1,348
I am storing values into an array. I am wanting to find an average of the highs and an average of the lows. Something like this... After 50...
Replies
36
Views
8,838
Hello, I been trying to sort some values in the the Do-more PLC but still have some issues. I have 20 elements from the data view with random...
Replies
9
Views
3,650
Back
Top Bottom