LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically build an array

Solved!
Go to solution

I want to dynamically build an array like in the image below. The problem I'm having is the previous element is being reverted back to zero after inserting a new element. Seem like it should be simple. What am I missing?

0 Kudos
Message 1 of 7
(4,042 Views)
Solution
Accepted by topic author RHutchings

Because the initialize array is inside the for loop, it's creating a new array of 0's every loop, getting rid of your old data.

 

You can move the initialize array outside of the loop and use a shift register to update the array using "Replace Array Subset", instead of "Insert into Array".

 

Alternatively, you could use auto-indexing to dynamically create the array without needing to initialize it first. This method is much simpler.

 

Build an Array

Message 2 of 7
(4,015 Views)

So what youre doing is initializing an array of N,5 in this case, to zero.  This creates an array of 5 elements that you set to 0. You then proceed to insert the iteration + 1 at index iteration + 1.  So after the for loop completes you have an element of 5 zeros and then you insert the final iteration (4) + 1.  This gives you an array of 0,0,0,0,0,5.  Exactly as it should.

 

Im assuming you want your final array to be 1,2,3,4,5? is that correct then you should initialized outside the array and then you need to place shift registers on the for loop and have that array go into and out of the replace array.Array.PNG



-Matt
Message 3 of 7
(4,014 Views)

If you want to make array of [1 2 3 4 5], just open Labview basics course and find what is "Autoindexing" of terminals in a For loop. 

0 Kudos
Message 4 of 7
(4,004 Views)

The autoindexing worked perfectly. Thanks you.

0 Kudos
Message 5 of 7
(3,981 Views)

How is it possible to build array from 70 to 30 for example ? Thank you

0 Kudos
Message 6 of 7
(467 Views)

@LilySamchuk wrote:

How is it possible to build array from 70 to 30 for example ? Thank you


Continued here.

0 Kudos
Message 7 of 7
(448 Views)