aledain Posted March 22, 2004 Report Share Posted March 22, 2004 I found this one today. Looks like it is "expected" behaviour because it is present in LabVIEW 5.11 too. Sigh could have saved me 2 hours of pain. Connect an empty 1 D array out through a FOR loop (indexing), thus creating a 2D array at the output. Create an indicator and get the "Array Sizes" of the array. Wire "N" of the loop with any number and run the VI. Note that the first element of the sizes matches "N" of the FOR loop, but the array in fact is empty! I can understand this in terms of the logic (ie the FOR loop does execute N times), but still reckon it should return 0 for the size of the array OUTSIDE the for loop. Imagine what happens when instead of an array constant, it's a subvi that only returns data some of the time. cheers, Alex. Download File:post-16-1079960881.vi Quote Link to comment
Jim Kring Posted March 22, 2004 Report Share Posted March 22, 2004 I found this one today. Looks like it is "expected" behaviour because it is present in LabVIEW 5.11 too. Sigh could have saved me 2 hours of pain.Connect an empty 1 D array out through a FOR loop (indexing), thus creating a 2D array at the output. Create an indicator and get the "Array Sizes" of the array. Wire "N" of the loop with any number and run the VI. Note that the first element of the sizes matches "N" of the FOR loop, but the array in fact is empty! I can understand this in terms of the logic (ie the FOR loop does execute N times), but still reckon it should return 0 for the size of the array OUTSIDE the for loop. Imagine what happens when instead of an array constant, it's a subvi that only returns data some of the time. cheers, Alex. Alex, I'm no computer scientist or mathemagician, but I agree that this is the "expected" behavior -- in fact, this is the same behavior as the build array function. Try buiilding a 2D array from two empty 1D arrays and the length will be [2,0]. I guess the moral of the story is to always test for an empty array, if it matters (good luck guessing when it will matter). The OpenG Toolkit has a VI called "Empty Array?", which tests if the Array Product == 0. Another interesting behavior is that if you wire an empty 2D array with dimensions [2,0] into a two nested For Loops with indexing enabled, the outer For Loop will iterate twice, outputing an empty 1D array on each itteration. Cheers, -Jim Quote Link to comment
Jim Kring Posted March 22, 2004 Report Share Posted March 22, 2004 Hmmm, makes me wonder if we need an OpenG Toolkit VI that will "Force Empty Array Lengths to Zero". Attached is an implementation of this idea (that I threw together from some existing OpenG LabVIEW Data Tools Vis). Obviously it will be much faster to do this using strict data types instead of Variants. You will need the OpenG Toolkit 2.x and specifically the LabVIEW Data Tools package (lib_lvdata) in order to use this example. Cheers, -Jim Download File:post-16-1079981323.zip Quote Link to comment
didierj Posted March 23, 2004 Report Share Posted March 23, 2004 Alex, This behaviour is not only in LV but "all" programming languages. Internally multiple dimension arrays are built this way: - each row of your 2d array is built as a separate 1d array containing the values of this row. the size of e.g. the first so created array is dimension M. - these arrays (or rows) are indexed in a separate array of pointers, each pointer pointing to one of the arrays mentioned above. the size of the pointer-array is the dimension N. Thus, a 2d array is an array of pointers pointing to a series of 1d arrays of whatever type - building a 2d array from empty 1d arrays gives you a dimension of Nx0. More complicated: a 3d DBL-array is an array of pointers pointing to arrays of pointers pointing to arrays of double values. Cheers, Didier Quote Link to comment
aledain Posted April 2, 2004 Author Report Share Posted April 2, 2004 Thanks Didier, I thought that it looked suspiciously like expected behaviour (from what I recall of CompSci). Still I think that when you're got a wire (bearing in mind that wire could be many miles long ;-)) when you test for length it should return 0 if it "knows" there is no physical data inside the array. LV itself knows this because the array indicator is greyed, whereas a traditional language might not have that, LV itself recognises the no data! cheers, Alex. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.