LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Check the length of a 2D array

Solved!
Go to solution

I am trying to check the length of a 2D array. I want to know if the array is empty. Isn't a 2D array an array of arrays? When I use Array Size on a 2D array I get another array with zeros. Is there some way to to tell if a 2D array is empty other than doing Array Size and the iterating the result for all zeros?

0 Kudos
Message 1 of 4
(1,718 Views)

There is an Empty Array primitive on the Comparison pallette.

 


@flycast wrote:

I am trying to check the length of a 2D array. I want to know if the array is empty. Isn't a 2D array an array of arrays? When I use Array Size on a 2D array I get another array with zeros. Is there some way to to tell if a 2D array is empty other than doing Array Size and the iterating the result for all zeros?


The array of zeroes that you are getting is an array of sizes of each dimension (so there will be two zeroes), so your array is empty.

0 Kudos
Message 2 of 4
(1,711 Views)
Solution
Accepted by topic author flycast

@flycast wrote:

Isn't a 2D array an array of arrays?


No.

 

A 2D array is an array with 2 dimensions, not a 1D array with arrays as elements.

 

The size in each dimension must be the same size, which is not true for an array of arrays (in for instance C\C++).

 

In LabVIEW, you have to make an array of clusters with an array to get an array of arrays.

 


@flycast wrote:

Is there some way to to tell if a 2D array is empty other than doing Array Size and the iterating the result for all zeros?


"Iterating the result for all zeros" would be a mistake.

 

A LabVIEW array can have a size in one dimension, and 0 in another. So the size array could be [0, 5] under some circumstances. It would be empty.

 

So if you wanted to check for emptiness with the size array, you need to check if one dimension is 0, not all.

 

You can Multiply Array Elements on the size array, and check if it's value is 0.

 

Obviously the Empty Array? function avoids all this.

0 Kudos
Message 3 of 4
(1,701 Views)

weibe@CARYA

 

Great Answer!!! I can see why you are a proven zealot!

 

Wow, I missed the Empty Array? function. That is Exactly what I need!

Thanks so much!

0 Kudos
Message 4 of 4
(1,644 Views)