03-20-2013 12:41 PM
Hi All,
I have an Array (Attached). I need to find the minimum number that is NOT zero.
Using the Array Max & Min returns 0 as the min. What I want is the next minimum number.
Thank you.
D
03-20-2013 12:45 PM
Hi,
What is your LabVIEW version ?
Are the Values in the 2D array always non-negative?
03-20-2013 12:52 PM - edited 03-20-2013 12:55 PM
To expand on Amitai's question, if the values are all >=0, then you can convert the array to an unsigned format and subtract 1. The zeros will all be turned to Max_INT (because unsigned arithmetic wraps around) and Array Max and Min will give you your value minus 1.
Even if they're not, you can simply convert this to a two step process - do AMaM and if the result is 0, do the step I described earlier. Otherwise, return the minimum value you got.
If you care about performance more, you might prefer to write code to explicitly index over the entire array, because it's quite possible that converting the array to unsigned will require either an allocation or touching every element of the array. That depends on the compiler and the way the values are represented in memory.
03-20-2013
12:53 PM
- last edited on
01-10-2025
02:07 PM
by
Content Cleaner
I don't know if that is the most effective way... but using the conditional tunnel output in a for loop just as shown here :
(added feature in LV 2012)
You can create an array without the minimum value and then using the Array Max & Min again .
Is that useful enough for your needs ?
03-20-2013 01:34 PM - edited 03-20-2013 02:07 PM
Do you also need the position of the found element? What if several numbers have the same minimum value?
If you just want the value of the smallest nonzero element, here's what I would do. All you neet to do is retain is a single number.
This assumes that your zeroes are really zero. With DBL you never know. 😄
03-20-2013 01:40 PM
03-20-2013 01:44 PM
Knight,
Yes i would also want the position of the found element.
I dont mind if there are other numbers with the same minimum value.
Thanks.
D
03-20-2013 01:54 PM - edited 03-20-2013 01:57 PM
My attempt without array functions (unless you count the greater than 0). Not sure if this works for all situations, I just wanted to try something different. It may also be a bit "rube-ish"
crap, while coding, Altenbach strikes again. Not to mention, his solution shows mine is rube-ish rubish as expected. Good to know about the Inf trick though.
03-20-2013 02:01 PM - edited 03-20-2013 02:03 PM
Daudo wrote:Yes i would also want the position of the found element.
Here's one possibility.... Modify as needed.
03-20-2013 03:53 PM
Hi again,
More questions (that might help to speed up the process) :
1. The numbers in the array are Integers ?
2. The array you gave as an example has a unique "diamond" shape for the non-zero values and also
for the non-zero values, the columns are sorted from big to small.
Is that the types of the array you are interested to perform this action to ?