10-13-2020 04:23 PM
This is for NXG.
It seems to me that when I run a VI troubleshooting values in arrays have somewhat unpredictable behaviour. If I run the VI there are times when there are more set values in an array then there should be.
In this case I have used three values when building the arrays:
1, 1, 0.
My logic creates the first row with the two 1's as expected.
The logic creates the second row but adds a zero on the end. It's seems like the second array at index 1 can't be shorter than the first array at index 0.
That red circled zero should not be there.
Here is a super simple example. The zero at the red arrow should not be there:
IF I am iterating the arrays in the bottom example how do I tell if that last zero is a real value or padding when the array was created?
10-13-2020 09:38 PM
Array are ALWAYS rectangular. You can't have a 3 element row followed by a 2 element row.
What you could do is initialize a large enough array with NaN as the element. Then use replace array subset to replace row 1, followed by row 2.
The "missing" element in your 2nd 1-D array should cause that element in the master 2-D array to remain NaN, which would be obviously not 0.
10-13-2020 09:46 PM
Arrays cannot have rows of different length; therefore, the Build Array function fills in for these cases.
I recommend you review the help document for this function: https://www.ni.com/documentation/en/labview/latest/node-ref/build-array/, especially the Details and Examples tabs.
10-14-2020 10:27 AM
OK, Thanks for explaining. I am making the transition from text based to LabView. In C# for instance you can have Jagged Arrays where the arrays have different lengths.
Two follow up questions and an observation:
Observation:
Doing the same thing with Waveform gets a different result. Each waveform is different length:
10-14-2020 11:01 AM
@flycast wrote:
OK, Thanks for explaining. I am making the transition from text based to LabView. In C# for instance you can have Jagged Arrays where the arrays have different lengths.
Two follow up questions and an observation:
- If I have an array of arrays with varying lengths of data how do I tell that the zero is a "padded" zero vs. real data?
- Is there a null in NXG that the array could be initialized with?
Observation:
Doing the same thing with Waveform gets a different result. Each waveform is different length:
Yes, LabVIEW cannot have jagged arrays. You cannot know if an array is padded with Build Array. You can put each subarray into a cluster (LabVIEW's "struct") and put THAT into an array, which will get you jagged arrays.
There is no NULL value but there is, as mentioned above, a NaN value. LabVIEW's doubles are IEEE-754 floating points, which doesn't have a NULL value.
https://labviewwiki.org/wiki/NaN
This works with Waveforms because you're making an array of waveforms, each of which can be whatever length you'd like. Similarly to above, you can make an array containing a cluster with an array in it. That's really a 1-D array of 1-D arrays, not a jagged 2-D array, but it's hopefully what you're looking for.