LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Function "Insert into Array" does not add dynamically generated arrays in a loop

I was able to track down my problem with a VI to the function "Insert into Array".
I am creating a 2D array by adding 1D arrays to an empty 2D array. It works fine as long as the 1D arrays are constant and do not change within a loop.
When I try to add dynamically generated 1D arrays in this loop, only the first time the loop runs they are added.

I attached a simple VI which shows the effect. Am I doing something wrong or do I misunderstand the way this function is working?
0 Kudos
Message 1 of 18
(9,110 Views)
That is indeed strange. I've stepped through it a couple of times and used probes. The results do not make sense. I think that you've found a bug. You should report this to NI through their support page.

In the mean time, I changed the "Insert Into Array" functions to "Build Array" functions with "Concatenate Inputs" turned on and this works as expected. I've included the VI with these changes. To get you going, try the "Build Array".

Rob
0 Kudos
Message 2 of 18
(9,110 Views)
Rob,

I doubt there is a bug. This function requires A) an array as an input, and B) an index of insertion. The implementation of this function in his code has neither. The code is trying to insert data into an array of 0 dimensions and 0 elements. This cannot possibly be done.
0 Kudos
Message 4 of 18
(9,110 Views)
Actually, I tried it with an index added and got the same results. The first time through, it works as it should and the second time through, the one dimensional array is created properly inside the loop (I was using a probe and it had 3 elements) and then when it is passed outside the loop, it becomes a zero dimensional array. The data just disappeared. Quite baffling. The fact that it works once then not twice is very strange as well. I kinda like consistency in my programming.

Rob
0 Kudos
Message 10 of 18
(9,110 Views)
Rob,

I'm not 100% sure, but I think I can explain why this behaves the way it does:

The function that is the loop receives an input of an array, which is empty. The array is dynamically modified, but all modifications are to an empty array. A dynamic build is never performed. I think the probes are seeing the right data, but when the data is output, the results are as they should be (in my opinion) because an insert into array is being peformed on a non-existent array. I suspect that the bug here is more related to allowing an array input that has no elements. I don't know how the developers would solve this. I am going to try something with the program, and see what results I get. I am going to try initializing an array
with 3X3 elements (all blank) and see what happens. Then I will add the indexing and see. I will report the results in a few minutes here...
0 Kudos
Message 11 of 18
(8,915 Views)
Okay, I initialized a 3X3 array, and didn't add indexing. I got some very weird results indeed. Not sure what to make of them. However; when I initalized the array, and then added the indexing the program worked exactly as it should (assuming that what is desired is a 3 dimensional array as the output, 3X5X3) However, when I kept the indexing and wired back to the blank array, I got nonsense, as is expected. I'm not sure what the bug is here, or if there is one, but I do know that in order to insert into an array, that there must be an array. The behavior is completely different between a 0X0 array, and an initialized array of 3X3.

Hope this is helpful.
0 Kudos
Message 12 of 18
(8,915 Views)
Rob,

thank you very much, I replaced the functions in my VI and all is working now.

I still have no idea if the "Insert into Array" behaviour is a bug or if I used it the wrong way. Anyways, my problem is solved with your answer, thanks!

Arne
0 Kudos
Message 13 of 18
(8,915 Views)
,

I looked at your code. There is something missing: you are inserting the arrays always in the same place. You need to wired the index of the loops to one of the dimensions of your array insert function. This will then concatenate your arrays. However; I cannot tell from your code exactly what you are trying to do. Your code inserts arrays into an empty array (not good programming methodology, you should use an initialized array with the correct number of elements) three times, each time inserting them in the 0,0 element.

LabVIEW has the ability to create arrays in many different ways. Static array manipulation is where an array is modified without changing it's size. This is more difficult to program, but results in much more efficient code
. A tradeoff that must be judged by each situation. Dynamic array creation is where LabVIEW creates arrays, each time reallocating new memory for the addditional elements and/or dimensions. This is far easier to program, but care must be taken to avoid catastrophic memory allocations, especially with large arrays and datasets.

I recommend searching through the array examples in the examples database. This is a very handy resource, and should be your first place to look to solve these types of problems.

Good luck
0 Kudos
Message 3 of 18
(9,110 Views)
If one more person puts a rating like this on my answers, I will just stop responding.

You don't encourage people to respond when you criticze (especially blindly) an answer that someone has sat down and thought about.

This forum is participated in by people volunteering their time to help others. If you have doubts about the answer, or don't like it, then comment. Don't just blindly insult someone who has taken the time to try to answer a question by rating it, despite it's accuracy.

-LabVIEWguru
0 Kudos
Message 6 of 18
(9,110 Views)
If one more person puts a rating like this on my answers, I will just stop responding.

You don't encourage people to respond when you criticze (especially blindly) an answer that someone has sat down and thought about.

This forum is participated in by people volunteering their time to help others. If you have doubts about the answer, or don't like it, then comment. Don't just blindly insult someone who has taken the time to try to answer a question by rating it, despite it's accuracy.

-LabVIEWguru
0 Kudos
Message 7 of 18
(8,925 Views)