LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Insert column instead of row in 2d array

Solved!
Go to solution

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?

0 Kudos
Message 1 of 11
(12,810 Views)

Transpose 2d array, insert a row, and transpose the array back? 

========================
=== Engineer Ambiguously ===
========================
Message 2 of 11
(12,807 Views)

Maybe I am not understanding the problem here....

Example_VI.png

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 3 of 11
(12,780 Views)

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.

0 Kudos
Message 4 of 11
(12,770 Views)

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

Message 5 of 11
(12,758 Views)
Solution
Accepted by Daikataro

Perhaps I am also misunderstanding the problem.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 11
(12,748 Views)

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.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 7 of 11
(12,742 Views)

@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.

Capture.JPG

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 8 of 11
(12,709 Views)

 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!

0 Kudos
Message 9 of 11
(12,703 Views)

@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.

0 Kudos
Message 10 of 11
(12,680 Views)