From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Finding the minimum number greater than zero in an array

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

 

0 Kudos
Message 1 of 27
(7,280 Views)

Hi,

What is your LabVIEW version ?

Are the Values in the 2D array always non-negative?

 

 

0 Kudos
Message 2 of 27
(7,269 Views)

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.


___________________
Try to take over the world!
Message 3 of 27
(7,259 Views)

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 :

 

http://zone.ni.com/reference/en-XX/help/371361J-01/lvhowto/condacc_valuesnloops/

 

(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 ?

Message 4 of 27
(7,255 Views)

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. 😄 

Message 5 of 27
(7,222 Views)

LabVIEW 2011.

 

No negative numbers.

 

Thanks

 

D

0 Kudos
Message 6 of 27
(7,210 Views)

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

0 Kudos
Message 7 of 27
(7,208 Views)

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.

0 Kudos
Message 8 of 27
(7,202 Views)

Daudo wrote:

Yes i would also want the position of the found element.


Here's one possibility.... Modify as needed.

 

 

0 Kudos
Message 9 of 27
(7,189 Views)

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 ?

0 Kudos
Message 10 of 27
(7,156 Views)