Select smallest value from an array

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-03 05:48 PM
I am trying to do something like the script in the image attached, but I get a strange error message (something like "incompatible arrow dimensions on line 8...", in Portuguese).
How could I get the smallest value in that array?
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-04 11:12 AM
min_value = somevalue[1] FOR i = 2 TO VARDIM1(somevalue) min_value = MIN(min_value, somevalue) NEXT i
Central Innovation

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-03 09:40 PM
min_value = 1000 FOR i = 1 TO VARDIM1(somevalue) min_value = MIN(min_value, somevalue) NEXT i
GDL object creation: b-prisma.de

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-04 07:23 AM
check_min = 1000000 !!some value larger than your expected minimum FOR i = 1 TO VARDIM1(somevalue) min_value = MIN(somevalue[1], somevalue) !!always check against first array value if min_value < check_min then check_min = min_value !!reset check_min to min_value endif NEXT i
Barry.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-04 11:12 AM
min_value = somevalue[1] FOR i = 2 TO VARDIM1(somevalue) min_value = MIN(min_value, somevalue) NEXT i
Central Innovation

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-04 11:48 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-16 03:46 PM
If you want to compareall array value at once, you will have to apply this approach, best if you can put it in a subroutine or even a macro
for __i = 1 to vardim1 (somevalues) step 1 !<-- step 1 is a redundancy to prevent errors in your code put somevalues[__i] !<-- puts all you values' array in the memory stack next __i min_value = min (get (nsp)) !<-- 1. Empties values from the stack to the min function !<-- 2. funtion export lowest value to parameterdon't forget to check GDL code style


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-16 03:58 PM
1. In Python, your proposed methods are considered to be similar to "lazy function", while mine is considered "eager" ... what is the impact of each method on the performance ? (considering that this method is applied with in the same GSM file)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-16 06:59 PM
Moonlight wrote:Comparing techniques between languages is not necessarily very helpful because they often vary too greatly in functionality and optimisation.
1. In Python, your proposed methods are considered to be similar to "lazy function", while mine is considered "eager" ... what is the impact of each method on the performance ? (considering that this method is applied with in the same GSM file)
On a purely algorithmic basis, the method you propose is certainly far more resource hungry and likely to be slower. Both iterate through an array of values using a loop, so will be identical from that standpoint. The primary difference is that former makes a less-than comparison whereas the latter is pushing a copy onto the stack. I think it's highly likely that making a copy will be slower. And ultimately the min function at the end of the method you propose will also have to repeat the same action, iterating through all the values to seek the lowest. So it could take twice as long and additionally consume as much memory as the original array. I can't really see an upside to that.
But in most languages, you would expect a 'min' algorithm that would operate directly on the original values (which is what the OP was hoping for).
Central Innovation

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-16 07:47 PM
What I'm asking, if there is a way to measure the performance of both methods?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-17 10:56 AM
Moonlight wrote:How would it be able to iterate over fewer values?
since the iteration will always be of a reduced number, I don't think that this will be of an issue.
Moonlight wrote:Just make a function in an object to iterate over the method thousands of time when a parameter is set/changed, time numerous runs and then average.
What I'm asking, if there is a way to measure the performance of both methods?
Central Innovation