LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to replace an element in an array that is actively getting bigger? I tried, but couldn't figure out how to do it.

Solved!
Go to solution

I was expecting array 2 to be filled with Gs, but instead I kept getting Bs. See attached VI

 

What I am getting:

GRCK5000_0-1692994354251.png

What I am expecting:

GRCK5000_1-1692994391080.png

 

Can someone please help?

 

 

 

0 Kudos
Message 1 of 4
(700 Views)

You did not realize that you're replacing an element that doesn't exist.

 

For an array of size 2, available indexes are 0,1 but you're asking to replace element at 2 which doesn't exist.

santo_13_0-1692995390180.png

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 2 of 4
(690 Views)

The last element of an array with size N has an index of N-1

 

While your entire code is a bit questionable, a quick Bandaid fix would be to insert a -1 in the right place:

 

altenbach_0-1693057001658.png

 

0 Kudos
Message 3 of 4
(629 Views)
Solution
Accepted by GRCK5000

@GRCK5000 wrote:

I was expecting array 2 to be filled with Gs, but instead I kept getting Bs. See attached VI


Then you need to program it differently because since you only keep the arrays of B's in the shift registers, the second output will have all B's, except for the last element, which will be G.

If you want an array of Bs and an array of Gs you either need to maintain two shift registers, or keep replacing all elements with each iterations.

 

Also note that the "in place element structure" is completely pointless, because "replace array subset" will do exactly the same and equally "in place". Of course since you are growing two arrays, the inplaceness is moot anyway.

 

Maybe you could take a step back and explain what you are actually trying to do (now how you want to do it!). What's the purpose?

 

Message 4 of 4
(624 Views)