cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Incremental including the first value being input

Solved!
Go to solution
Highlighted

Incremental including the first value being input

Hi, i am trying to get a incremental of 8 from 1 to 201. However in my VI, i can only get values of 9, 17, 25... 201. I do need the values  1 for the output in my VI. Please assist me, much help is appreciated! 

0 Kudos
Message 1 of 7
(274 Views)
Solution
Accepted by topic author etedwin
08-12-2017 10:49 AM

Re: Incremental including the first value being input

Branch from  the upper wire before the "+" (instead of after) and iterate once more, i.e. 26 times.

 

ramper.png

Message 2 of 7
(251 Views)
Solution
Accepted by topic author etedwin
08-12-2017 10:49 AM

Re: Incremental including the first value being input

Allow me to restate your problem slightly -- create an Array starting with 1, incrementing by 8, and ending with 201.  You are given the starting value, the increment, and the ending value, but not the size of the Array.  This formulation screams "While Loop", not "For Loop".

 

While (and For) loops have Shift Registers to hold intermediate values, such as the successive values of the Array elements.  Your problem says that the Starting Value (of the Shift Register) is 1, so wire 1 into the Shift Register before the loop starts.

 

The problem says "Add elements to make an Array", so you want to take the value in the Shift Register and bring it to an output Array Tunnel (also called an "Indexing Tunnel").  It also says to increment the value for the next loop by 8 (note the implicit "order of execution" -- use, then modify).  Finally, it says to Stop when the value being output = 201 (though it would probably be a good idea to stop if the value >= 201, just in case someone can't add properly).

 

Try putting these words into LabVIEW code.  When you get another problem that involves sequential loops, use the same kind of logical thinking and you'll "do the right thing".

 

Note that if the problem said "Starting with 1, generate an Array of 26 numbers incrementing by 8 each time", the "natural" choice (since you don't have an Ending Value, but rather N) is a For loop.

 

Bob Schor

0 Kudos
Message 3 of 7
(243 Views)

Re: Incremental including the first value being input


Bob_Schor wrote:

Allow me to restate your problem slightly -- create an Array starting with 1, incrementing by 8, and ending with 201.  You are given the starting value, the increment, and the ending value, but not the size of the Array.  This formulation screams "While Loop", not "For Loop".

 


No, the number of iterations can be determined from first principles giving the inputs, thus a FOR loop is correct. It is basic math to determine N before the loop runs.

Message 4 of 7
(235 Views)

Re: Incremental including the first value being input

A while loop can also be very dangerous for pathological inputs. Imagine the user accidentally enters a negative increment. The while loop will never stop because the condition can never be reached (well, once the I32 wraps around because of overflow, but that's not desired Smiley Very Happy).

 

Here is some simple code. It can easily be expanded to deal with (start>end + negative increment). You also need to decide what should happen if the range is not evenly divisible by the increment.

 

ramper2.png

Message 5 of 7
(233 Views)

Re: Incremental including the first value being input

And nobody mentioned the Ramp Pattern.vi?  Yes, what you need is already done for you.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines

The discussions from the Advanced User Track is not over. Join in the conversation: 2016 Advanced Users Track
Message 6 of 7
(179 Views)

Re: Incremental including the first value being input

Ramp is DBL. This seems to be a blue problem Smiley Very Happy

0 Kudos
Message 7 of 7
(175 Views)