07-19-2012 12:41 PM
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.
07-19-2012 12:47 PM
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.
07-19-2012 12:47 PM
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.
07-19-2012 04:09 PM
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.
07-19-2012 04:17 PM
@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.
07-19-2012 04:38 PM
...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...?
07-19-2012 04:43 PM
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.
07-19-2012 05:00 PM
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.