From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array data overwritten by null value

Solved!
Go to solution

I am working on writing a VI that simulttaneously reads velocity and pressure, then records them on separate arrays.  Ran into a wall at about 90% of the way through.

 

The data (represented by the random numbers for testing's sake) comes into this central case loop then to an "add to array" VI.  Here is where it gets sticky:  When I use a null value at the start of this array (top highlight) my data continuously gets overwritten on the "row 0" of the array every loop.  But when I leave out the null value (bottom highlight) my data is added to the array just fine, but when I stop the entire VI and restart it, the new data values are just added to the bottom of the array.  Any help would be appreciated.

 

Forgive my caveman drawings of a VI, learning the system on my own, and just getting to the optimization point.  Thanks!

 

-Powderman

Array Issue.JPG

0 Kudos
Message 1 of 5
(2,560 Views)
Solution
Accepted by topic author Powderman

Hello Powderman,

 

What you've (perhaps accidentally) done is created an uninitialized shift register, which will retain its value until the VI leaves memory. This can be an extremely powerful tool and can be leveraged to create things like Action Engines, but if you need to clear data between runs you'll need to do some extra work.


It sounds like what you want to do is maintain your array value while the application is running, but clear it when restarting the application- is that correct?

 

If that's the case, then you have a few options.  My recommendation would be to leave the loop uninitialized and use the "First Call?" primitive to check whether or not this is the first time your processing loop has iterated and replace the "used" array with an empty, null array.

 

You could also consider using globally-initialized feedback nodes, or a half-dozen other methods that have various pros and cons.  Congratulations on working through the application, by the way!

Tom L.
Message 2 of 5
(2,543 Views)

Feedback nodes did the trick!  My arrays erase correctly after each program restart and log the data sequentially as it should.  Thank you Tom L. for the fast and helpful response!  Off to finish this thing!

feedback node.JPG

0 Kudos
Message 3 of 5
(2,532 Views)

You can now get rid of those while loops.

 

Also, you are better off using Build Array rather than Insert into Array for those 99% of the times where you want to put your new elements at either the beginning or the end of the existing array.

Message 4 of 5
(2,530 Views)

Any more of these shortcuts and I won't have anything left!  Thanks RavensFan for helping me clean things up, and for it still working!

 

Simple.JPG

0 Kudos
Message 5 of 5
(2,511 Views)