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: 

adding data to an array dynamically

How do I add an element after every fourth element of a dynamic 1D array?
0 Kudos
Message 1 of 7
(2,868 Views)

What is a dynamic 1-D array?  Are you talking about a 1-D array of the dynamic data type?

 

To add an element into a 1-D array, you need to use the Insert Into Array function.

0 Kudos
Message 2 of 7
(2,853 Views)

1.png

 

Something like this?

 

 

I am pretty sure there is a simpler way of doing this...This is what came to my mind randomly

 

 

 

Regards
Guru (CLA)
Message 3 of 7
(2,851 Views)

Let me redfine the problem.

 

I have an array which is being populated continuously by a bit stream (a sequence of complex numbers). I have to insert a complex number after every 4th element of this array. Is this clearer?

Thanks 

0 Kudos
Message 4 of 7
(2,844 Views)

I have an array which is being populated continuously by a bit stream (a sequence of complex numbers). I have to insert a complex number after every 4th element of this array. Is this clearer?
So whats wrong with the logic provided in the previous post?
Regards
Guru (CLA)
0 Kudos
Message 5 of 7
(2,842 Views)

Dhiraj wrote:

Let me redfine the problem.

 

I have an array which is being populated continuously by a bit stream (a sequence of complex numbers). I have to insert a complex number after every 4th element of this array. Is this clearer?

Thanks 


Show the code that you have now that shows how the array is being populated.

 

What you can do is maintain a shift register like Guru showed you.  Every time a new element is added, increment the shift register.  You can also use the Quotient remainder function to divide by 4 and always increment the remainder.  Whenever the remainder is zero, then add your extra element.

 

Guru's code looks correct, but if you are adding just one element at a time (instead of acting on a whole array at once as he shows), then you just need to implement the inner part of his code into yours.

0 Kudos
Message 6 of 7
(2,817 Views)
A performance note - please do not put a Build Array primitive into a loop.  This fragments memory and kills preformance.  Check here for some much faster alternatives (although more complex).
0 Kudos
Message 7 of 7
(2,812 Views)