LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error: Array keeps adding to itself overtime I press "run"... Please help!

I'm not sure if I posted this in the right spot if I didn't than I apologize.

 

My program I wrote was made to take a long list of data points gathered from a wavelength spectrum. Since I'm only interested in looking at a specific area of the spectrum to see how much of a substance is present when the light is shown through, I want to shorten the data points too a limited frame with.

 

My program works fine for the most part, like if I run it with only taking in 3 data points starting at a specific point it does it fine, however if i click run again than it attaches the same three data points after the initial three. this repeats for however many times i click it.

 

LabView Error pic.png

 

If anyone might have an idea of whats going wrong I would greatly appreciate it

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

I've asked a moderator to move your post to a more appropriate forum -- this is for ideas for new features for LV.

 

However... your bug is the feedback node. You're never initializing it so it remembers the value from the previous run.

 

I recommend you stop using feedback nodes here and instead use a shift register, as you did for the line below. Outside the loop, initialize the shift register with an empty array.

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

AristosQueue wrote:

I recommend you stop using feedback nodes here and instead use a shift register, as you did for the line below. Outside the loop, initialize the shift register with an empty array.


Or just right-click the feedback node and select "move initializer one loop out". Now right-click the initializer terminal sitting on the while loop boundary and select "create constant", thus creating en empty 2D array constant.

 

This can be done much more easily by eg. A "reshape array" function, replacing the entire while loop! Also, "index array" is resizeable, no need to have two instances. Try to turn the entire thing into a one-liner. 😄

 

Can you attach your actual VI and some typical data and control values? (What is X? What is numeric? What is the size of the initial 2D array?)

 

Also, your VI has no safety net! For example if the number of elements is odd, you loop would run forever and the VI would need to be aborted.

Message 3 of 5
(3,516 Views)

Hi Brandon,

 

Welcome to the LabVIEW forums!

 

Both AristosQueue and Altenbach's suggestions are great, and I am partial to the loop-initialized feedback node:

 

Untitled.png

In this case, however, it probably makes more sense to use a shift register for the generated 2D array because you're using the data outside of the loop.

 

Altenbach's suggestion to use the reshape array function is spot-on.  I think this would replace most of the code you've shown.

 

Regards,

Tom L.
0 Kudos
Message 4 of 5
(3,502 Views)

Looking more at your code, there is even more silliness. WHy are you appenting at the beginning (much more inefficient), just to have to reverse the columns at the end?

 

Please attach your code as requested. I am usre the entire thing could be doen in one or two simple operations.

0 Kudos
Message 5 of 5
(3,480 Views)