LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

output values from a for loop for each iteration

I have a for loop VI attached. My Question is that without indexing the output from the for loop will be the value from the last iteration and with auto indexing the output would be an array with each element corresponding to a value of that iteration. I would want to get the output from the for loop "on the fly" as in for each iteration my output indicator should change with the value from that iteration (equivalent to having an indicator inside the for loop and constantly monitoring the output. But in my case I want it outside the for loop).

Any help will be appreciated. Thanks.

-Sreekar
0 Kudos
Message 1 of 10
(5,382 Views)
You must write to the indicator inside the loop, you can do this by either placing the indicator inside the loop as you mentioned or using a Local Variable of the indicator, or write to the indicator using a reference.

Message Edited by AndrewAlford on 04-03-2007 08:49 AM

Andrew Alford
Production Test Engineering Technologist
Sustainable Energy Technologies
www.sustainableenergy.com
0 Kudos
Message 2 of 10
(5,379 Views)

That would make life so much more easier. But the thing is that I would be using that value outside the loop in an other VI. And I cannot use the Array Indexing because both the VI's kind of work hand-in-hand, a Master-slave kind of operation u can say. So the first VI which has the loop sends out the value to the second VI, processing/measurement and then the next value.

-Sreekar

0 Kudos
Message 3 of 10
(5,376 Views)
Why don't you place the other VI inside the loop?
Andrew Alford
Production Test Engineering Technologist
Sustainable Energy Technologies
www.sustainableenergy.com
0 Kudos
Message 4 of 10
(5,373 Views)
Hi Andrew,

It's like a management/ senior level kind of decision where each one needs to be independent and more generic. Something like that.:(

-Sreekar
0 Kudos
Message 5 of 10
(5,368 Views)
I agree, the easiest thing is to put the other VI in this loop. If for some reason you don't want to do that, use a queue. Attached is a modified version of your code that has a separate loop running which reads the value of the iterator outside of the for loop. Put this in your other VI to run it simultaneously with the for loop. Check out the example finder for more queue examples if you don't have experience with them.
0 Kudos
Message 6 of 10
(5,366 Views)
Hmmm... I think I can use queues. Thanks Marc. i think that should keep me going for sometime ...Does the same idea work for Nested For loops too??. Do we queue the element inside hte inner most loop?

-Sreekar
0 Kudos
Message 7 of 10
(5,349 Views)
And does it work if I have the entire VI as a sub VI and use it in an other VI. For eg: in the For_Loop_question_2 which mark posted if I make it as a sub VI with the "Iteration value" as pin and call it in another VI does it still update that indicator?

-Sreekar
0 Kudos
Message 8 of 10
(5,347 Views)

You can enqueue the element wherever it makes sense in your program. If you want to nest for loops and queue the inner most iterator, that will work fine.

As far as using the value in another sub VI, you can just create the queue outside of both of them. Send the queue reference in to both the sub VI generating the numbers and adding them to the queue and the other sub VI which dequeues each value. You can't simply wire the value that is dequeued out of the while loop and out of the sub VI to read it anywhere else while it's being updated.

I think it would be beneficial for you to read up a little more on dataflow programming. You have to realize that structures don't output anything until the code inside them is finished.

0 Kudos
Message 9 of 10
(5,344 Views)
Yeah, I think I know what you mean when the Q reference should be outside both the VI's. Thanks a lot. Will definately read more on dataflow programming.

Thanks,

-Sreekar
0 Kudos
Message 10 of 10
(5,336 Views)