LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Putting a row in 2d array

Hello,

I try to insert a 1d array into a 2d array. I use the "Insert into array" function, but it just refuses to do it. I wire the output array to a local variable of the 2d array, but it just won't work. Help!
0 Kudos
Message 1 of 4
(3,053 Views)
Do you do it the way illustrated on the attached picture?

If you try to insert on a row index that is more than +1 of the row size of the existing 2D array it won't work..in other words, if the 2D array is empty you have to insert at row 0, if it has 2 rows you have to insert at row 0, 1 or 2...etc.

I suspect your code could be improved; using locals and doing array inserts are things that normally are avoided in good code...
0 Kudos
Message 2 of 4
(3,053 Views)
Thanks for the reply!

Yes, that's the way I do it, now. First I tried to initialize an array, insert my element in there, and insert that into the 2d array, but that didn't work. Now I use a temporary array, and insert my element in there.

I'm very,very new to labview (I normally use C/C++ or Delphi at school), so why are local variables and array inserts avoided? Yes, I'm pretty sure my code can be improved, as it is quite confusing now 😎

and another question... How can I insert an element into a 2d array? The way I do it now, is I take the row I want out of the 2d array (using index array), delete that row from the 2d array, insert my element in the indexed row, and insert the row back into the 2d array, and return that. This doesn't seem to resi
ze the 2d array (like the help-function said it will do), as I can only see the newly inserted value...
Thanks in advance!
0 Kudos
Message 3 of 4
(3,053 Views)
Array inserts makes the whole array rescale, it involves creating a copy of the original array, so it is avoided because it requires more memory and is slower than initializing the array to it's final size straight away and then replace elements (To know how large a part of the array has actually been filled with real data, if that is necessary to know, add a counter/counters...). I have attached an example.

Locals and globals are avoided for many of the same reasons; they create copies of the data and are slow...they also allow race conditions (no guarantee that the data is read/written in the correct order...) Locals can normally be avoided just by using data flow; use the wires to hand over data, do not write or read it using locals. They ha
ve their place though, e.g. if you need two parallel loops to share data, but in many cases it's better then to use what is called a functional global.

Read more about this on:

http://zone.ni.com/devzone/conceptd.nsf/webmain/732CEC772AA4FBE586256A37005541D3?opendocument&node=DZ52068_US


http://zone.ni.com/devzone/conceptd.nsf/webmain/82E60E34E609C22A862569F8007E3F4A?opendocument

http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=506500000008000000637D0000&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0&USEARCHCONTEXT_QUESTION_0=Do+not+use+locals&USEARCHCONTEXT_QUESTION_S=0
0 Kudos
Message 4 of 4
(3,053 Views)