LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with shift-register and "insert into array"

First sorry for my bad english Smiley Indifferent

I have a problem using the "insert into array" in combination with shift-registers.

I'm using a loop with a shift-register. The shift-register is initialized with an array with one element. Every loop-step a number is inserted to the existing array and the new array is connected to the shift-register. Here's the problem:
If the index of "insert into array" is connected to a constant everything works fine, but if i connect it to something variable (like the iteration terminal) the result is an array with just two elements.

In my example the output-array should be [0 1 2 3 4 5 6], but it is [0 1]

Where is my error in reasoning?

0 Kudos
Message 1 of 13
(6,474 Views)
Delete the connection to the Index input of Insert into array. Look at the help file for that function.

Lynn
0 Kudos
Message 2 of 13
(6,451 Views)
The vi is just a simple example. I don't want to attach an element everytime. When I connect a dynamic generated number (from 0 to the size of the array) i got this problem.

I'm using this to sort an array of clusters.


0 Kudos
Message 3 of 13
(6,446 Views)
To elaborate on Lynn's reply, "Insert into Array" does just that, it inserts into a predefined array.  If your array isn't big enough, you can't insert into it.  As Lynn said, if you delete the connection to the index input, it will simply add the element to the end of the array.  In order to index each input, you could use "Initialize Array" to create an array that has at least 5 elements.  You could also use "Build Array" instead and wire the shift register to one input and the iterator to another so that the value of I gets appended to the end of the array.
Message 4 of 13
(6,446 Views)
Sorry I didn't see your last reply when I posted.  The reason your output array is only 2 elements is that you index your original array and only pass in the first element to the shift register.  You need to give it a bigger array in order to insert into it.
0 Kudos
Message 5 of 13
(6,441 Views)
Thanks for your answers.

But I thought I'm indexing the array from the last loop-step (therefor the shift-register). The help says, insert into index resizes the array.
And why has the output-array of the following vi a length of 6?

The only thing I changed is the index-source.
0 Kudos
Message 6 of 13
(6,433 Views)
This gets you the solution you were looking for.  Hope this helps.  Sorry I am butting in I am new to this forum but thought I would help.
0 Kudos
Message 7 of 13
(6,427 Views)

@foenig wrote:
.....
I'm using this to sort an array of clusters.

You can use the 'Sort 1D array' function: it sorts an array of clusters according to the first element of the cluster.


-Franz
0 Kudos
Message 8 of 13
(6,423 Views)
FWIW, if you want to add to an array at an arbitrary index location then you need to do something like the attached VI...
0 Kudos
Message 9 of 13
(6,385 Views)

"But I thought I'm indexing the array from the last loop-step (therefor the shift-register). The help says, insert into index resizes the array.
And why has the output-array of the following vi a length of 6?"

It will resize the array if the insert actually works.  The problem is that you can't for example, insert an element into index 4 of an array that has less than 5 elements because index 4 doesn't exist.  You changed your example to always insert into position 0, so it will keep adding at the front of the array and push the other elements down.

Make sense?

0 Kudos
Message 10 of 13
(6,377 Views)