10-12-2020 10:19 AM - edited 10-12-2020 10:19 AM
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?
Solved! Go to Solution.
10-12-2020 10:24 AM - edited 10-12-2020 10:27 AM
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.
10-12-2020 10:42 AM - edited 10-12-2020 10:44 AM
@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.
10-12-2020 02:09 PM
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!