LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to iterate through multiple variables?

I need to iterate through three different variables (arrays), and was wondering what the best way to do this would be? I am more familiar with C than I am with LabVIEW at this point, but am getting up to speed on LabVIEW pretty quickly. Normally in C, I would just create three nested loops, but I am wondering if this is the best method in LabVIEW or not. I could use a state machine I think, which would give me some flexibility in re-arranging the order of iteration or adding or subtracting variables easier than working with nested loops I think...anyway, I'm open to suggestions.

0 Kudos
Message 1 of 8
(3,912 Views)

Nested loops are fine if that is how the data needs to be accessed. A state machine certainly is more flexible but may be overkill for this. If the data in the arrays is independent (which sounds like they are not in your case) you could process each array in parallel.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 8
(3,910 Views)

There's nothing wrong with nesting for loops.  You just autoindex on the loop you want the variable to index through.  I'm guessing you will also need shift registers to keep a value that you are changing.  This is not an uncommon setup.


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
0 Kudos
Message 3 of 8
(3,909 Views)

Your question may stem from your unfamiliarity with LabView.  Labview does do some things differently than text based languages, but many things you will find have the same functionality and use.  Nested loops do and yes, this would be the preferred way of iterating through an array.  But this will also depend on what you intend to do with the data.  Code the way you think.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 4 of 8
(3,870 Views)

@R.Gibson wrote:

I need to iterate through three different variables (arrays), and was wondering what the best way to do this would be?


Arrays are not "variables". can you be a bit more specific.

 


@R.Gibson wrote:

I could use a state machine I think, which would give me some flexibility in re-arranging the order of iteration or adding or subtracting variables easier than working with nested loops.


 Why does the order matter? Rearranging in what way? If you do autoindexing, it will just iterate over all elements until it runs out of elements.

... And again, what do you mean by "variables"?

 

It would help if you could show us a VI containing some typical input data in controls (make current value default, save) and explain what kind of output you expect.

 

 

0 Kudos
Message 5 of 8
(3,862 Views)

...sorry, I am mixing my terminology a bit. I was considering each array mathematically to be a variable, as in each element is variable, not referring to local or global programming variables. Basically, I am doing an automated test for a power supply, and I need to change input voltage, output voltage and load current, and test at each case. By changing the order of iteration, I was referring to which "variable" I change first, be it Vin, Vout, or Iout. Perhaps it would have been better to use the term "parameter" instead of variable...?

 

It seems like if I do a nested loop, it might make it difficult to change the order of iteration, whereas if I do a state machine, I could easily re-configure the order. Not that it makes much difference right now, I'm just trying to think ahead a bit. Also, lets say we want to throw in another parameter, like ambient temperature, a state machine would probably make including that parameter to the program flow easier...?

0 Kudos
Message 6 of 8
(3,858 Views)

You might also consider storing your test parameters in a .txt or .cfg file for easier access and updating instead of hard-coding them.  You should also supply the tolerances with the parameters.  Perhaps you're already doing this, I don't know what your front end looks like or how you have it coded.  Just a thought.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 7 of 8
(3,852 Views)

I haven't coded it yet, I am just beginning development. Good idea on the text file input, I hadn't thought of that yet.

0 Kudos
Message 8 of 8
(3,845 Views)