07-16-2013 03:09 PM
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).
07-16-2013 03:18 PM
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.
07-16-2013 03:30 PM
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.
07-16-2013 03:39 PM
Right click the build array function and choose the concatenate inputs option...
07-16-2013 03:46 PM
Thanks that seemed to work, turning the output into a 1D array. However I am still concerned about the efficiency of this method.
07-16-2013 03:51 PM
It is as efficient as it can possibly be.
Why do you have concerns?
07-16-2013 04:14 PM
@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.
07-17-2013 07:51 AM
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).
07-17-2013 08:39 AM - edited 07-17-2013 08:41 AM
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.
07-17-2013 10:12 AM
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.