I'm trying to get the median value of an array in codesys, however the array is fifo, so as a new value is added to the array the first value is deleted and the median is rechecked. The array is always going to be odd in size and I think IQueue will be useful but the codesys sp16 documentation are not very descriptive about how to use it. Any ideas?
Asked
Active
Viewed 111 times
0
-
By median do you mean the middle value in your queue, or the middle value in the sorted array of the queue? If the latter, you'd need to sort the queue every time you want to calculate the median – Guiorgy Nov 15 '22 at 11:37
1 Answers
0
The functionblock Queue implements the interface iqueue. See here for more documentation: https://content.helpme-codesys.com/en/libs/Element%20Collections/Current/ElementCollections/Function-Blocks/Queue/Queue.html
In my opinion the Queue could be used to manage adding and removing values with fifo. However to calculate the median value a seperate function is needed that just iterates over all the values in my opinion. The library 'ElementCollections' does not facilitate automatic median value calculation.

Jouke Aalvanger
- 1
- 1