LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI of the Day (11/5/2009) - Quotient & Remainder

Today we have the versatile function "Quotient & Remainder".  This guy finds its way into many a for loop or while loop when you want to repeat a set of indices (say 0,1,2,0,1,2...).  Or, let's say you need to know the fractional part of a number, just divide by 1 and take the remainder, plus you get the integer part as well.  Finally, it's simple to check if a number is even and to pad it to the next even number if necessary.  I am sure there are a few more clever uses.

 

QuotientRemainder.png 

 

VIOTD groundrules here

Message Edited by Darin.K on 11-05-2009 09:07 AM
Message 1 of 6
(3,882 Views)

The use of Quotient & Remainder with floats has been brought up before for those who intend to delve into that deep pool.

Example: http://forums.ni.com/ni/board/message?board.id=170&thread.id=163975

Message 2 of 6
(3,873 Views)

If you want to perform an action every n-th time a loop iterates, do wire the i terminal to the Q&R and the remainder to a case structure selector term. Use case 0 for the action. 

 

Felix 

Message 3 of 6
(3,870 Views)

Another typical use is an integer division where we need to increment by one in order not to lose the data in the remainder if there is one (e.g. when reshaping a1D array to a 2D array and the last row will be only partially filled.)

 

I usually use the following construct.

 

Message Edited by altenbach on 11-05-2009 08:00 AM
Message 4 of 6
(3,843 Views)

I think the first time I really used the modulo function (as it is called in other languages), I used it to alternate the background color of rows of a table from a database query.  /sigh at NI for not letting me alternate the background color of a table, or an array.

 

The text "modulo" in the Search Palettes feature, should point to the Quotient & Remainder function, but alas, it doesn't.

 

You gotta appreciate the fact that there is an actual function to the remainder of an integer based division operation in programming.  I remember learning about it in elementary and then it was never mentioned again until college.

 

 

Edit: Spelling.  I wish my web browser's spellcheck function worked on the NI forum ><.

Message Edited by Nickerbocker on 11-05-2009 10:06 AM
Message 5 of 6
(3,814 Views)
I remember using this for making a led blink continously. Used this inside a while loop.
0 Kudos
Message 6 of 6
(3,727 Views)