LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

return specific value from array

Solved!
Go to solution

I have a set of code that returns an array of two values. The next step in my code is to choose only one value based on a set of rules:

If both items are equal, return either one of the values.

If exactly one item is equal to 12, return the remaining value (12 could be in the first or second position)

Otherwise, always return the largest value.

 

I can map this out in my head and it seems fairly straightforward, but when I try to turn it into code, it becomes more complicated.

 

I have attached my attempt. Am I overthinking this?

 

Thanks for any help.

0 Kudos
Message 1 of 5
(2,146 Views)

c

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 2 of 5
(2,139 Views)
Solution
Accepted by topic author MTHPCB

First of all, use the Array Max & Min to get the largest value.  Coincidentally, if they are equal, the Max and Min will be the same value.  So finding the Max will suffice for cases 1 and 3.  So really, we just need to figure out if one of them is 12.  Compare the array to 12.  This will give you a boolean array.  Now use the Boolean Array to Number to get a number and wire that number to a case structure.  If the number is 1, then the first value was 12 and you should return the second value.  If the number is 2, then the second value was 12 and you should return the first value.  If the number is anything else, return the max of the array.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 5
(2,139 Views)

Thanks. That is definitely much cleaner than I was making it.

0 Kudos
Message 4 of 5
(2,112 Views)

For some reason I was thinking about this problem while washing the dishes and came up with another solution.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 5
(2,094 Views)