LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a range of values to run in a for loop

I am currently trying to run a case structure inside a for loop under a certain range of values. My question is how do I create a range of values between the iteration mines a value of x where the case value will run for one value, and then when the range is exceeded (again i-x) the case structure will be changed to another value?

 

Thank you in advance and I am a relatively new user to labview.

0 Kudos
Message 1 of 10
(5,053 Views)

A simple state machine is all you need.

 

Please be much more specific. What are the values? Are they increasing monotonically? Unless you can calculate the total number of iterations based on the values of the array you cannot use a FOR loop. I assume you have an array of values, so instead of a case structure, just use "index array" and change the index to the next element when appropriate.

 

It usually help if you would attach some code (even incomplete) so we have a better picture on what you are talking about.

0 Kudos
Message 2 of 10
(5,039 Views)

I have attached the file. 

 

I am basically trying to run the loop for a set amount of iterations (in this case 200) and have the case value be false until it reaches a range of values in which case there will be a true value.

 

I would then like to add another case structure for when it reached 200 to run another sub vi within the case strucuture.

 

Thank you again for any help you can provide.

0 Kudos
Message 3 of 10
(4,991 Views)

All you probably need is a single case structure connected to [I], but that's not very flexible. Are the ranges always the same? (Sorry, on the phone. Cannot look at code).

0 Kudos
Message 4 of 10
(4,979 Views)

No the ranges can change. I think you might have a better idea when you see the simple code.

0 Kudos
Message 5 of 10
(4,975 Views)

I had a look at it.

 

First, you're using a While loop, not a For loop.  For loops are for when you know exactly how many iterations you want before you start, and While loops are for when you're not sure and you want to check a condition.  Which better suits you?  (Note that you can choose to terminate a FOR loop early as well).

 

Next, you're doing floating point math and then comparing it to an integer loop value.  Big no-no.  You'll want to change that at the very least to a "greater than or equals" because the instant you have any input that's not a whole number you're never going to pass the equals check.  A better want would be to change the representation of all your numbers that should only be integers to I32s to force them to be that way.  Right now if you try to run this with an acceleration time with anything other that an integer number of seconds it will never match equality.

0 Kudos
Message 6 of 10
(4,971 Views)

OK, looking at the code:

  • So why is it now a while loop instead of a FOR loop?
  • Simply create a ramp array from the inputs and autoindex on a FOR loop.
  • What are the array values at the various switching points and how are these points entered?
  • What determines the loop timing?
0 Kudos
Message 7 of 10
(4,969 Views)

Thank you. I meant a while loop.

 

What about creating a range of values?

0 Kudos
Message 8 of 10
(4,961 Views)

Here's a simple draft that might give you some ideas....

 

0 Kudos
Message 9 of 10
(4,959 Views)

Thank you very much! I'm looking through it now and will probably have questions later on!

0 Kudos
Message 10 of 10
(4,953 Views)