LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem Re-Initializing Arrays

Solved!
Go to solution

When I write an expression in my program ("2+2-1" for example) I want my program to make an array of all numbers in the expression (2,2,1) and an array of all operators in the expression (+,-).

The program does that successfully. HOWEVER, when I input an expression and then run the program multiple times, the arrays stack the newer values on top of the old ones.
What I want the arrays to do is NOT to stack the values up, but to reset to their default values in the beginning of each run of the program. I'm a beginner in LabVIEW and I could not find a solution that I could understand. I tried everything: initializing a shift register connected to the array, using an invoke node, initializing via an empty array constant, etc. I wasted hours on a matter which should be trivial. 

I uploaded a simple version of my program. Please modify it so that the arrays always start from their default values (which are the "empty" values).
I must be missing something fundamental but I simply could not get it to work.

0 Kudos
Message 1 of 8
(3,797 Views)
Solution
Accepted by topic author I_want_Bagels_In_Me

Right-click the intializer terminal for your feedback nodes and choose Create constant, it will create an empty array.

 

That should solve your problem.

 

mcduff

snip.png

 

 

 

 

 

 

Message 2 of 8
(3,781 Views)

I must confess that Feedback Nodes always confuse me -- I do understand the idea, I just find Shift Registers and While Loops easier to grasp.

 

That being said, look at the bottom of the Feedback Loop (point your mouse there on a Block Diagram).  See the little (unwired, in your code) terminal called "Initializer Terminal"?  Wire your desired Initial Value there, and see if that fixes your problem.

 

And don't worry -- unexpected terminals in LabVIEW functions eventually Byte all of us on the behind ...

 

Bob Schor 

0 Kudos
Message 3 of 8
(3,773 Views)

Okay wow. I knew my problem was stupid, but I didn't think it was this stupid. I can't believe I failed to grasp something so simple haha. Thank you guys! I would've spent many more annoying hours on this issue without your help!

0 Kudos
Message 4 of 8
(3,767 Views)

@Bob_Schor wrote:

I must confess that Feedback Nodes always confuse me -- I do understand the idea, I just find Shift Registers and While Loops easier to grasp.


Ditto.  Especially when used in conjunction with a while loop.  If you already have a while loop, why not use shift registers? 

aputman
0 Kudos
Message 5 of 8
(3,694 Views)

aputman ha scritto:

@Bob_Schor wrote:

I must confess that Feedback Nodes always confuse me -- I do understand the idea, I just find Shift Registers and While Loops easier to grasp.


Ditto.  Especially when used in conjunction with a while loop.  If you already have a while loop, why not use shift registers? 



I thought the same until a few days ago. Then I realized that one of my Shift Register values was used only in a very small portion of the loop structure. Replace it with a Feedback Node and - voilà - I got rid of a long wire with less clutter in the block diagram!

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 6 of 8
(3,690 Views)

@pincpanter wrote:

I got rid of a long wire with less clutter in the block diagram!


I avoid long wires by keeping my diagrams and loops small.  If you have to scroll to see where a wire leads, you most likely have chosen a poor architecture or your wiring is just sloppy. 

 

Feedback nodes can be stashed away in some far corner of a while loop and there is no visual indication of dataflow and IMO, they seem to break dataflow by routing a wire back into itself.  That goes against all that is right and good.  However, with shift registers, you can clearly see that there is data coming into the loop and it's easy to follow the logic.  Personal preference I guess.

aputman
0 Kudos
Message 7 of 8
(3,680 Views)

As has been discussed before, there are subtle differences between SR and FN (e.g. the two modes of "global initialization" for the FN). Yes, a FN can often be contained entirely in one case of a case structure which often makes simpler code. Still,  we lack some functionality that would make this scenario even better. I typically use SRs for the main state machine, but FNs everywhere else.

0 Kudos
Message 8 of 8
(3,679 Views)