LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Building array without initializing?

Is it possible to build an array without first initializing an empty array outside my loop. (i.e. in Matlab you can simply just type a vector in, it is not necessary to create an empty vector first). I'm using a VI to record encoder positions and want to just add onto the end of the array each time through the read loop, but I'm not sure how big the array may end up to be. I know I could just make a very large array but then I have to deal with all the trailing zeros which I don't feel like doing.
 
Thanks
 
Tim
0 Kudos
Message 1 of 5
(3,955 Views)
What you might try, is to have an indicator inside your loop for the encoder position (if you want to see the data real time), and then with the same wire, wire it to the wall of the loop, and right click->enable indexing.  That will build your array to whatever size you wish (number of loop iterations - I'm assuming only one read per loop iteration), with all your data in it, and no trailing zeros.

Your array however, will only be available to you after the loop is complete.  Let us know if you need something more...

Hope this helps.
0 Kudos
Message 2 of 5
(3,953 Views)
I assume you are building your array in a shift register. You need to initialize with an empty array (Size zero!) or the shift register will retain the data from the previous run.
 
I really don't understand your problem. Initializing your shift register with an empty array is peanuts. Just do it and don't worry about it.
 
Be aware that building an array in a loop can cause performance issues because more memory needs to be allocated as the array grows. However, there will never be any "trailing zeroes".
 
(If you want to be more efficient AND you know the final array size, you should initialize the shift register with an array of the final size (containing all zeroes or INF, for example). Then you can use "replace array element" at the desired indes as you go. SInce you don't know the final size, you cannot do this)
 
A finite size array filled with zeroes is very different to an empty array, is it possible that you confuse the two? 😉
 
Describe in more detail what you are actally doing, how you are building the array, etc. and we can give more detailed help. 🙂
 
What are your typical upper arrray size limits? (a few hundred? a few hundred million?)
0 Kudos
Message 3 of 5
(3,946 Views)
Or if you are using a while loop you could use the build array function and a shift register.



Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 4 of 5
(3,946 Views)
The main point here is I believe the fact that adding values to an array in LabVIEW will automatically increase the size of the array.

This is great for exactly your case where you don't know how large the array will be.  Just keep appending to the array and at the end you have the array with the right size.  You can initialize with a zero-size array, it doesn't matter because LV will size it for you.

I think this may be the reason you're afraid to initialize an array?

Hope this helps

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 5 of 5
(3,929 Views)