LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI of the Day (10/20/2009) - Select

Today it is the "Select" function.  A very common task is to select between two values, and this function does that in a tidy little package.  And unlike the case structure, we can easily see what both choices are on the BD.  What you end up with is clean, easy to understand code, what could possibly be wrong with that?  There is one very important difference between the case structure and the select function, the case structure only evaluates the required case, both cases are evaluated in the Select function.  Usually the difference in negligible, or you are choosing between two values that you have calculated anyway.  However, a common case where there could be a difference is choosing between an array and the same array with a new value added.

 

Select.png

 

The memory allocation for Build Array goes on in every loop regardless of whether or not it is the desired outcome.  In a case structure, only necessary allocations are performed.  Don't ask me what this code does or does not do, it is pretty much random. 

 

One thing I sometimes do, but haven't tested is to have build array in every cycle, but choose to append either the new value built into a single element array or an empty array.  I assume that appending an empty element doesn't force any memory allocations, but I haven't tested it.  I try to stick to case structures now.

 

Select2.png 

 

Crazy, the array constant is wired to the SR and the node on the while loop, but LV won't show it when I copy.

 

VIOTD groundrules here.

Message 1 of 7
(3,438 Views)

Just small addition: this function also works with Error clusters (some time ago the nugget was already posted here), for example:

 

error select.png

 

Andrey.

Message 2 of 7
(3,416 Views)

Darin,

 

When do we get the VIOTD for the Implies primitive?

 

I have never used this, and cannot think of a single instance where it simplfies logic. Tomorrow's topic perhaps? 😉

0 Kudos
Message 3 of 7
(3,389 Views)

nrp wrote:

Darin,

 

When do we get the VIOTD for the Implies primitive?

 

I have never used this, and cannot think of a single instance where it simplfies logic. Tomorrow's topic perhaps? 😉


That would make a good VIOTD.

 

I don't want to preempt a future VIOTD.  If you search on implies, I think you'll find some good messages from Dennis or one of the other knight's or near knights that explains it pretty well.  But it can be used for detecting a given transition like a True to False Transition or a False to True Transition where one of the inputs comes from a shift register.  I can't remember which, and the few times I've used it, I've had to find the truth table and work it out.  And it almost always seemed like the logic was the opposite of what I wanted.  Ultimately, I usually just make my own using a compound arithmetic and inverted inputs or outputs as needed to work for whatever my logic case is.

0 Kudos
Message 4 of 7
(3,381 Views)
There was a nugget about the Implies primitive. Like Ravens said, the compound primitive is easier to understand.

___________________
Try to take over the world!
0 Kudos
Message 5 of 7
(3,369 Views)

Ravens Fan nailed it, before the whistle this time.  Smiley Wink  The implies function seems like a perfect VIOTD, and I may still have to get to it someday.  However, I came across this thread from a more reputable source.

 

http://forums.ni.com/ni/board/message?board.id=170&message.id=194432&query.id=1230994#M194432

 

Still, it may prove hard to resist.

 

As for tomorrow, my single-handed attempt to rescue the US airline industry continues as I am off on another trip.

 

Edit:  Thanks TST, looks like I came in after the whistle this time...

Message Edited by Darin.K on 10-20-2009 02:16 PM
0 Kudos
Message 6 of 7
(3,368 Views)

I actually remember seeing that nugget now that it is mentioned. I didn't really get it then and I still don't get it... but am more than happy with using compound logic instead...

0 Kudos
Message 7 of 7
(3,334 Views)