Luchek Posted September 19, 2016 Report Posted September 19, 2016 Hi guys, I'm using a Schneider Electric M340 PLC, I have a multi-dimensional array: Array[1..10,1..10] of real. To give a little background. Each of those 10 arrays contains 6 parameters for a controller. They're run through a test and the score is recorded in the 7th element. Now my problem is I need to sort those 10 arrays based on that 7th element. More specifically I need to pluck the best two performing ones and write them to a new array set.. I've tried writing my own sorting algorithm although I only manage to take the first, best performing one as opposed to the top two. This of course is programmed in ST. Any advice would be appreciated, Kind regards, Max Quote
panic mode Posted September 19, 2016 Report Posted September 19, 2016 once you have determine first one (the best), store it someplace else, then set all of its elements to zero for example (in the list of 10). then repeat search for next best case.... 1 Quote
Luchek Posted September 19, 2016 Author Report Posted September 19, 2016 .........that's smart... Can't believe I didn't think of that! Thank you, legend. Quote
Luchek Posted September 19, 2016 Author Report Posted September 19, 2016 I guess one more question though..the way I determine the best is by just taking the MIN(value1, value2,etc...) So If I set it to 0..it will be the best. Would setting it to 99999 work as well? Quote
panic mode Posted September 19, 2016 Report Posted September 19, 2016 that depends on your values. suppose you have values 1,2,3,4,5,6,7,8,9,10 if the "best" is smallest value, your first search will return "1". to prevent it from being selected again, set some large value such as 99999. this way next search will find "2" as a next best result. if the "best" is largest value, your first search will return "10". to prevent it from being selected again, set it to some large negative value such as -99999. this way next search will find "9" as a next best result. Quote
panic mode Posted September 19, 2016 Report Posted September 19, 2016 you don't have to really modify original data, you can of course just mark it and exclude from next search. reason i mentioned modification of value is because you already have working code and this would allow it to run again without any code modifications. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.