LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Incremental including the first value being input

Solved!
Go to solution

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
(1,453 Views)
Solution
Accepted by topic author etedwin

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

 

ramper.png


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
Message 2 of 7
(1,430 Views)
Solution
Accepted by topic author etedwin

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
(1,422 Views)

@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.


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
Message 4 of 7
(1,414 Views)

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.

 

ramper2.png


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
Message 5 of 7
(1,412 Views)

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


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 6 of 7
(1,358 Views)

Ramp is DBL. This seems to be a blue problem 😄


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 7 of 7
(1,354 Views)