08-12-2017 11:34 AM
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!
Solved! Go to Solution.
08-12-2017 12:24 PM - edited 08-12-2017 12:28 PM
Branch from the upper wire before the "+" (instead of after) and iterate once more, i.e. 26 times.
08-12-2017 12:43 PM
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
08-12-2017 12:54 PM
@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.
08-12-2017 01:09 PM
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 :D).
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.
08-12-2017 09:16 PM
And nobody mentioned the Ramp Pattern.vi? Yes, what you need is already done for you.
08-12-2017 09:24 PM
Ramp is DBL. This seems to be a blue problem 😄