LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Arrays (Vectors in C++) in LabVIEW?

I have several VIs that collect data from muliple sources. I would like to make a single logging VI. The data VIs would pass it an array of the values but since they each contain a different number of elements the logging VI won't accept the array if it's a different size than it expects. I would like to know how to make it so that it will accept an array of any size or expand the array to fit the array it's being passed so it can parse it properly.

Very similar to a vector in C++
0 Kudos
Message 1 of 8
(5,170 Views)
You can either make all arrays twodimensional or have two different inputs in your logging vi. One for 2D arrays and one for a 1D array. Internally you can build a 2D array from the 1D array or simply add the 1D to the 2D existing array(using build array).
You can look in the simple array to textfile vi for the first solution.
greetings from the Netherlands
0 Kudos
Message 2 of 8
(5,170 Views)
That's not quite my problem.

I don't have multiple arrays that I'm passing, rather a single array who's dimensions are unknown.

Is there anyway to pass an array whos dimensions are variable to another VI?

Ex. the array in the subVI can expand to fit the array being passed.
0 Kudos
Message 3 of 8
(5,170 Views)
You say its a single array but how does a single VI create an array output that varies its dimension? Are we confusing number of dimensions with number of elements?
0 Kudos
Message 6 of 8
(5,170 Views)
Albert Geven gave you a good suggestion that can be applied in general.
But if you have a n-D array where n is variable, an alternative idea would be formatting this array into a speadsheet string and sent it to the remote vi.
You can progammatically format it according to n dimension, then append to the string the n value so that the remote vi can unformat it automatically according to n.
If you have large arrays this causes a little overhead to your program, but it's an idea.
0 Kudos
Message 4 of 8
(5,170 Views)
Ok perhaps my question or comments were not clear or misleading ... but it is not dimension that is variable. It's the elements. If the array is 1D or even 2D (ALL the arrays will either be 1D OR 2D, but not both) I don't know how many entries are associated with it.

It may have 10 elements, it may have 30. I want the VI that it's passed to be able to handle both arrays not knowing prior how big the array is.
0 Kudos
Message 5 of 8
(5,170 Views)
Let me see if I got it now.
You have a vi that collects data for instance in 1D array and you want to share them in another vi, you don't know how many data the array contains, is it right?
If this is right, then you don't have to worry about it because each 1D array in a remote vi will re-dimension itself automatically according to the number of elements (array size)from the origin array. The same of course applies for any n-Dimension array.
0 Kudos
Message 7 of 8
(5,170 Views)
I don't see what the problem is then. You don't have to allocate the number of array elements in LabVIEW. The array control on the subVI will be empty until it is passed some data and then it have the number of elements of the calling VI. If, for example you want to log each array element, wire the array control to a for loop. Inside the for loop put a write function. The for loop will auto index the array and run n times where n is equal to the number of elements. If you need to know the number of elements for something, just use the Array Size function
0 Kudos
Message 8 of 8
(5,170 Views)