LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Resetting array values to default before running VI - How?

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.

 

Image 24.png

 

Here is a super simple example. The zero at the red arrow should not be there:

Image 27.png

 

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?

0 Kudos
Message 1 of 5
(1,709 Views)

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.

0 Kudos
Message 2 of 5
(1,662 Views)

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.

0 Kudos
Message 3 of 5
(1,660 Views)

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:

 

  1. 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?
  2. 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:

Image 28.png

0 Kudos
Message 4 of 5
(1,632 Views)

@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:

 

  1. 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?
  2. 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:

Image 28.png


 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.

0 Kudos
Message 5 of 5
(1,625 Views)