LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

filling a 1-D array

Solved!
Go to solution
I am prototyping an encoder with a simple adder function in a while loop, that increments every 1/4 second. (This part works). I want LabView to automatically put each of these values in consequtive elements in an array. I have tried the "Insert Into Array function", but it doesn't want to work for me. How can I do this?
0 Kudos
Message 1 of 11
(7,916 Views)
Use the Build Array function.  I have rarely used the Insert into Array.  It can easily fail on you if you try to insert into a location that doesn't exist.
0 Kudos
Message 2 of 11
(7,915 Views)
Almost, So I got the Build array functiont to insert the elements into the array, but it just puts them all in the '0' element. How do I make the inputs be in consequtive elements?
0 Kudos
Message 3 of 11
(7,911 Views)

HI,

 

Take 1D array constant outside the loop and connect this to while loop and change the terminal to shift register. After this use build array function in first element of build array connect shift registers input and connect your data to second terminal, and then output of build array function give to output terminal of shift register.

 

you can monitor the data at the end of build array function, hope this helps

Regards

Santosh

Message 4 of 11
(7,897 Views)

I think this is what's suggested in previous post.

 

You'll ofc need to change my integer to your values.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 5 of 11
(7,882 Views)

If you want to intereactively built the array inside the loop, you need to built it in a shift register or feedback node, e.g. as follows.

 

Message Edited by altenbach on 02-05-2009 12:00 AM
0 Kudos
Message 6 of 11
(7,879 Views)
Solution
Accepted by topic author mldelibero

thanks guys, So i finally got this one solved. My function now sequentially fills a 1-D array with values.

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

Then mark which ever reply best answered your question as the solution rather than your own reply.

 

By the way, instead of doing an addition of 1, there is a +1 increment function on the numeric palette to do it in one step.

Message Edited by Ravens Fan on 02-05-2009 01:23 PM
0 Kudos
Message 8 of 11
(7,843 Views)

mldelibero wrote:

thanks guys, So i finally got this one solved. My function now sequentially fills a 1-D array with values.


 

 There are a couple of problems with your solution:

 

  • You need to initialize the upper shift register with an empty array, else subsequent runs during the same session will append to the old data. (RIght-click the left shift regsiter...create constant).
  • Your array potentially grows without limits. You could potentailly run out of memory.
  • Growing an array in a loop is inefficient, because each resizing operation forces a new allocation in memory. This is OK for limited sizes.
  • I would recommend a feedback node (see above) once you add more code to all this. Less telephone wires across the while loop.
  • ...

 

 

Message Edited by altenbach on 02-05-2009 10:45 AM
Message 9 of 11
(7,838 Views)

Right, I see what you are saying about initializing, that did fix one of the bugs.

 

I did try the feedback loop inside of a while loop. It appears to work exactly the same as my previous loop (which is good). How is this more efficient? One of the reasons that I orrinally chose to continuously resize the array is that I will not know how many times that it has to run beforehand.

0 Kudos
Message 10 of 11
(7,821 Views)