LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there anyway to pass something like an array of arrays generically?

If I want to accept an array of integers in a subVI, its easy enough: drop an array, put in an integer control, and wire the array to the connector. I don't have to specify how many integers are in the array, so the subVI can act generically and loop over the integers in the array.

Now, suppose I want to generically act over a list of arrays. LabVIEW does not support arrays of arrays, so I can't accomplish this using the obvious approach. Now, I could accomplish this using an array with multiple dimensions, HOWEVER I'd have to "hard-code" that number of dimensions. Is there a way to do this generically?

Any ideas welcome.

Thanks,

Brad
0 Kudos
Message 1 of 9
(3,559 Views)
Maybe I'm missing something here, but isn't an "array of arrays" just a 2D array? That is, if arrays are 1D. If you have a bunch of 1D arrays couldn't you just combine them into a 2D array and pass that into your sub-vi? The only reason it would have to be bigger than 2D would be if you had multiple multi-dimensional arrays. Please let me know if I am way off on this.

Brian
0 Kudos
Message 2 of 9
(3,559 Views)
Actually, you're right. That will work for me, and its less painful than flattening to a 1d array.

I was confused because I'm really trying to represent an nD array using n+1 1D arrays (1 array for each of the n independent variables, and one array for the dependent variable).

Being able to pass the generic nD array around as a 2D array allows me to do things like implement a generic search algorithm that doesn't care how many dimensions there are (it just loops over each).

Thanks for the help.

Brad
0 Kudos
Message 6 of 9
(3,559 Views)
Glad I was able to help. Hope it works out for you!
0 Kudos
Message 7 of 9
(3,559 Views)
Bmarsh writes:

> If I want to accept an array of integers in a subVI, its easy enough:
> drop an array, put in an integer control, and wire the array to the
> connector. I don't have to specify how many integers are in the
> array, so the subVI can act generically and loop over the integers in
> the array.
>
> Now, suppose I want to generically act over a list of arrays. LabVIEW
> does not support arrays of arrays, so I can't accomplish this using
> the obvious approach. Now, I could accomplish this using an array
> with multiple dimensions, HOWEVER I'd have to "hard-code" that number
> of dimensions. Is there a way to do this generically?

The official way to do it is via LV 6 Professional where you can
create "variant" date types.

A poor
man's approach is via "flatten to string" and to wire the
binary string and the type description and to "unflatten from string"
that in the sub vi.

The real difficulty is to process the "undimensioned" array itself. If
you have the dimension length numbers (eg. 2*3*3 integers) you can try
to put everything into a 1D array and process that via manual
indexing.

Johannes Nie?
0 Kudos
Message 3 of 9
(3,559 Views)
I'm not clear on how using a variant would help me. I'd pass a variant into the subvi, but to do operations on it, I'd have to turn it into its "real" type but to do so I'd need the type information. I'm not clear how I could do all this generically.

My original thought is your last idea, put everything in a 1D array, and keep track manually where each "sub array" ends. This is a pain (and its a real pain that LabVIEW doesn't support this better), but it will work.

Thanks,

Brad
0 Kudos
Message 4 of 9
(3,559 Views)
Embed the array in a cluster and the you can have an array of clusters of array. Unlike the 2D array, individual arrays can have different sizes.

Jean-Pierre


LabVIEW, C'est LabVIEW

Message 5 of 9
(3,559 Views)
Brad,

I included an example that will demonstrate the use of clusters to make an array of arrays, please open the VI and run it, you'll see the explanations inside. For help in clusters please check your LabVIEW Help File it has very good information about them. The answer from Jean-Pierre is reflected also in this example that I'm attaching. Good luck!

Nestor Sanchez
Applications Engineer
National Instruments
Nestor
0 Kudos
Message 8 of 9
(3,559 Views)
I don't think your method is what he was looking for because you have a set number of arrays in the cluster. He was looking for a more generic method where he didn't know the total number of arrays. I also don't really think that it is what Jean-Pierre meant either. If I understand him correctly, he meant to put a single array in a cluster then stick that cluster inside of another array. That way you have an array of arrays essentially. I think the attached more closely reflects his idea.

Brian
0 Kudos
Message 9 of 9
(3,559 Views)