Showing results for 
Search instead for 
Did you mean: 

Most efficient to combine arrays

Hi there,


I have what seems to a a relatively simple problem, but I need some help.  I want to know what is the most efficient way to combine arrays that contain large amounts of data and are being combined within a while loop.  Currently I am using the insert into array function to combine the arrays, however I read one of the white sheets that talks about optimizing memory in LabVIEW and it advises to avoid this method when dealing with large amounts of data.  I also looked at the In-Place Structure but I do not think this contains the funciton that I need (which is combining arrays).

0 Kudos
Message 1 of 24

Give some details on what you mean by combining arrays.  Are you interleaving rows or columns?  Are they 1-D or 2-D?  Are you just appending one array to the end of the other?


Give some simple examples of what the 2 arrays look like before and what they should look like after.


Generally when working with arrays, you are better off doing the work within For Loops rather than while loops.  Since you know the size of the arrays before starting, LabVIEW can work with the memory layout more efficiently.  While loops imply an indefinite number of iterations, and the LabVIEW compiler won't be able to set aside the appropriate amount of memory up front.


Also, I find Insert into Array is almost always the wrong function to use.  99.9% of the time, the Build Array function is the correct choice.

0 Kudos
Message 2 of 24

What I mean by combining arrays, is placing the data from one array at the very beginning of another array.  Also the arrays are 1D.  I have tried the build array function however it turns my 1D into a 2D array. 

0 Kudos
Message 3 of 24

Right click the build array function and choose the concatenate inputs option...

0 Kudos
Message 4 of 24

Thanks that seemed to work, turning the output into a 1D array.  However I am still concerned about the efficiency of this method.

0 Kudos
Message 5 of 24

It is as efficient as it can possibly be.


Why do you have concerns?

0 Kudos
Message 6 of 24

@kevin_khan wrote:

Thanks that seemed to work, turning the output into a 1D array.  However I am still concerned about the efficiency of this method.

If you know the final array size, it is significantly more efficient to allocate the full size array once, keep it in a shift register, and use "replace array subset" to fill with valid data.

0 Kudos
Message 7 of 24

Hi guys,


I think I might have found the error in my code.  I was a birt concerned about my programs efficiency because I found that my program seemed to run significantly slower as time went on.  I thought that this might have been linked to the fact that I was building an array within a loop.  However the real problem with my code is related to a shift register within the while loop.  I misunderstood something about the shift register.  I thought that it carries over data from the very last iteration, however it seems to carry data over from all the iterations.  What I want is to carry data over from just the very latest or most recent iteration.


I am not sure how I can accomplish this, and was wondering if anyone would have an idea.  I can try and include a picture of my code, if it might help (I do have some custom made subVIs within this section of code).

0 Kudos
Message 8 of 24

Your shift registers are doing exactly what you wired them to do.  You are passing an array, then adding a new element to that array with each iteration.  Also, this while loop will run as fast as the computer allows which will generate very large arrays very quickly (unless your read buffer subvi has some timing control or wait functions).


What I want is to carry data over from just the very latest or most recent iteration.

This means you will just have two data sets (current iteration and previous output from the subvi).  If this is what you want, just wire the output of the read buffer subvi to the shift register.  Each iteration will then have access to the data read during the previous one.

0 Kudos
Message 9 of 24

Perhaps I am doing something wrong because I think that the data from each iteration is accumulating when I use the shift register.  For example I expect the array size for each iteration to be around 4000 elements.  However for the second iteration the array size is almost doubled, around 8000 elements, and it will continue with this trend.  But like I said perhaps I am forgetting something important.

0 Kudos
Message 10 of 24