LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to insert elements into an array after each iteration of a for loop

Solved!
Go to solution

I am new to labview and working on an application where I am supposed to store an element into an array (without overwriting) after each iteration in a for loop. I have tried using Build Array Function keeping the indicator outside the for loop and played with indexing but didn't work. Please suggest me an idea how to do it.

Thanks

0 Kudos
Message 1 of 7
(11,736 Views)

Several methods. Here are the most common:

 

FillArray.jpg

 

The best way is obviously the auto-indexing method.

0 Kudos
Message 2 of 7
(11,724 Views)
Thank you for your suggestion.Here is my actual application attached . In the first image, a difference in time is evaluated and an enum const of insert into array is passed to the shift register where it takes to Insert element into array phase (Second image). I need to enter the time difference into an array after every loop iteration. Please have a look and could you let me know where I am mislead.
Download All
0 Kudos
Message 3 of 7
(11,716 Views)
Solution
Accepted by Roxasarous

It would be better if you attached the actual VI.

 

Neither of your images show an "insert into array" operation.

0 Kudos
Message 4 of 7
(11,697 Views)

The problem with your framework is that you lose your information each time you change of case in the case structure.

 

So you need to keep your array in memory by using a 'shift register' as

 

FillArray.jpg when you need to fill your array

 

and

 

FillNotArray.jpg in all other cases

 

 

Don't forget to link the node for all cases of case structure (don't use ' Use default if unwired')

 It's a typical use of shift register 😉

 

Message 5 of 7
(11,693 Views)
Here is the work attached. I have done the work as directed. Could you check the program.
0 Kudos
Message 6 of 7
(11,673 Views)

Does it work for you now?

 

You should probably mark J.Dechet's reply #5 as the solution as he was the one who figured out from the screenshots that you were missing the shift register.

 

I would recommend trying to avoid the local variables.  Wire the times into other shift registers to carry them from iteration to iteration.  You can connect the indicator to the wire through the shift register to update the screen display.  As the very least, rename those time indicators to something more meaningful than Current Time, Current Time 1, Current Time 2.  It will help the local variables that you are currently using make more sense.  Such as Switch 1 High Time, Switch 1 Low Time.

 

I don't know what your code is supposed to do as it seems to run instantly.  I don't know the reasoning why you have the For Loop around your state machine's while loop.

 

It seems to me that if you are trying to act on switch changes, you should be using an event structure to detect when the switches are toggled.

0 Kudos
Message 7 of 7
(11,656 Views)