03-23-2016 01:02 PM
Greetings everyone. Probably the answer is pretty simple but I can't seem to find out how to insert a 1D array as a column instead of a row for a 2D one. I mean it in the sense of keeping the unwired behavior of the "insert into array" function, that appends the new element to the end of the array instead of replacing an existing element, since it only accepts row by default and, if I wire column, it won't append new elements, but will only attempt to overwrite existing ones and if it finds an empty column, will write nothing. Any ideas?
Solved! Go to Solution.
03-23-2016 01:06 PM
Transpose 2d array, insert a row, and transpose the array back?
03-23-2016 02:26 PM
Maybe I am not understanding the problem here....
03-23-2016 02:37 PM
Indeed you're not. What you're doing in that snippet, is inserting a predefined column into a predefined array, in a predefined position. What I want to do is to dinamically create an array, with undefined dimension that starts out empty, and appends new elements to first empty column it finds. So for example I have a completely empty 2D array, I generate a 1D array of data and want to append that as a column, instead of a row (default insert into array behavior) and so on.
If you wire index to the insert into array function, it will only attempt to overwrite the wired row or column you selected, but if it finds an empty row/column it will do nothing, and won't append data to the next available empty column.
03-23-2016 02:50 PM
Insert into Array by will not expand an array. It cannot insert into an empty column or row.
Build Array will append or prepend to an existing (even empty) array. You may need to Transpose to get the data where you want it, as has already been mentioned. Transpose is very fast and does not move data in memory. It just manipulates indexes.
Generally it is poor practice to have growing arrays, regardless of dimension. Why? Because arrays in LV must occupy contiguous memory locations. So a growing array requires continual re-allocation of memory. Quite often the availablility of an adequately large block of contiguous memory becomes a problem before the size of the array is more than a small fraction of the total memory.
It is better to allocate an array of a size equal to or larger than the largest array you expect to create. Initialize Array will do this. Then use Replace Array Subset to place your data into the array. At the end of the process, the final array can be trimmed using Array Subset if needed.
Lynn
03-23-2016 02:59 PM - edited 03-23-2016 02:59 PM
Perhaps I am also misunderstanding the problem.
03-23-2016 03:03 PM
Please provide some specific data that shows the final output of the array and the steps necessary to achieve it. Your explanation is clear as Mudd.
03-23-2016 04:52 PM
@Daikataro wrote:If you wire index to the insert into array function, it will only attempt to overwrite the wired row or column you selected, but if it finds an empty row/column it will do nothing, and won't append data to the next available empty column.
Are you sure that you're using the correct VI? What you describe here is how Replace Array Subset functions. These two functions look very similar.
03-23-2016 04:56 PM
Indeed Cross hit the nail in the head, that's exactly what I wanted to do, seemingly my explanation wasn't clear, glad you picked it up. Index array however WILL expand an array; "If you do not wire any index inputs, the function appends the new element or subarray to the end of the n-dim array" and while dynamically allocated arrays are indeed a problem when you're developing for FPGA applications, they're usually not much of a concern when running a regular one, and this development is not planned for FPGA so a dinamically allocated array that appends as colums, not rows, is exactly what I was looking for. Thank you everyone!
03-23-2016 06:02 PM
@Daikataro wrote:so a dinamically allocated array that appends as colums, not rows, is exactly what I was looking for. Thank you everyone!
Compared to appending rows to a 2D array, appending columns It is in fact a huge concern, even with relatively small arrays. Whenever you insert or append a column to a 2D array, almost all elements of the 2D array need to be touched and moved in memory while appending a row can leave the existing elements untouched as long as there is sufficient preemtively allocated slack at the end. It is almost always much cheaper to append rows. You can always transpose once you are completely done.