LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

nested for loops outputs in single array

hi,

   I have a while loop which has to stop after 5 iterations,in which i have 2 for loops in a while loop.Each for loop has to run 2 times each. The output of each for loop has 2 values and one value coming from the first iteration of while loop so total 5 values.Now i want to store all these values in a single 1-D array format,which i am not able to do. i am unable to store all the values in a single array .Can anyone guide me in doing this

0 Kudos
Message 1 of 5
(3,714 Views)

You could resize the output array or use a shift register in the second for loop instead of indexing, make sure you append the new value to the old array.


CLA CTAChampionI'm attending the GLA Summit!
Subscribe to the Test Automation user group: UK Test Automation Group
0 Kudos
Message 2 of 5
(3,711 Views)

@Samineni wrote:

hi,

   I have a while loop which has to stop after 5 iterations,in which i have 2 for loops in a while loop.Each for loop has to run 2 times each. The output of each for loop has 2 values and one value coming from the first iteration of while loop so total 5 values.Now i want to store all these values in a single 1-D array format,which i am not able to do. i am unable to store all the values in a single array .Can anyone guide me in doing this


I am not sure what you mean by "nested For loops."  Nested in the while loop or one For nested inside another, which is the traditional term.  The attached VI probably will not give you your expected results, but it will give you an idea of how to use indexing and shift registers to build arrays, which is your main question.

It would help if you could attach a VI so we can get a better idea of your code.  You are not very clear in your original post regarding your design.

Keep in mind, there are actually two programs in the attached VI which is the reason for two stop buttons, but this was just to demonstrate different methods, not be familiar with your design.

-----------------------------------------------------------------------------------------
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 3 of 5
(3,694 Views)

Samineni wrote:

   I have a while loop which has to stop after 5 iterations, ,in which i have 2 for loops in a while loop.


That means it actually should be a FOR loop, right?

 


@Samineni wrote:

Each for loop has to run 2 times each. The output of each for loop has 2 values and one value coming from the first iteration of while loop so total 5 values.Now i want to store all these values in a single 1-D array format,which i am not able to do. i am unable to store all the values in a single array .Can anyone guide me in doing this


If both inner for loops spin exactly twice, couldn't you place all code is a single FOR loop? Or are they nested too?


So, do you want to append 5 elements to a 1D array with every iteration of the outer loop (final size 25 elements), or do you want to overwrite a 5 element 1D array with every iteration of the outer loop (final size 5 elements)?

 

What should be the order of the five element sets?

 

As you can see, a text description is typically not sufficient to unambiguously describe a VI. it would be significantly easier for all of us if you could attach a simple draft of your code. 

 

 

 

 

 

0 Kudos
Message 4 of 5
(3,681 Views)

Maybe something like this?

 

 

0 Kudos
Message 5 of 5
(3,677 Views)