LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Insert into an array

Solved!
Go to solution

Hi guys,

 

I am stuck, I have attached a vi. can someone please help me understand how to make that work. I have a 2-d Array and I want to insert an 1-d array into a defined column. I know the column number. I am 1 month old to Labview so I am sure I am overlooking something very simple.  

 

Thank you for the help,

0 Kudos
Message 1 of 7
(8,409 Views)

Hi Rugan,

 

You must to initialize the 2D array first. Then you can insert into 2D array the 1D Array in the column index (or row index). I share with you this VI Snippet that show some similar. I hope this help.

 

Regards,

 

Sebastian 

0 Kudos
Message 2 of 7
(8,398 Views)

Hi Sebastianm127,

Thank you for responding. The way you do it doesn't work for me. I made another VI removing most of the sections and all the instruments and kept what matters here. When I press the button "Take reading" it should populate the following row in the column is on. When I press the Button "Next Column" it should go to the following column and will populate this column from Row 0 when pressing "Take reading" button. this will continue for 1000's of times over and over.  

 

Thank you,

0 Kudos
Message 3 of 7
(8,328 Views)

Probably caused by race conditions through the abuse of local variables.  You have no control over the order a local variable is written to or read from.  Particularly in that last sequence frame.  You don't even need sequence frames if you replace the read of local variables with a wire that is sourced back to where the data was created.

0 Kudos
Message 4 of 7
(8,311 Views)
Solution
Accepted by topic author Rugan

Your first code shows two uses "insert into array" and "replace array subset". They do very different things. Often the task is to append a new row to the end of a 2D array, so "built array" is the right choice.

 

Insert into array: Does nothing if the array is small compared to the insert point, otherwise it inserts a row/column, moving all higher rows/columns to a new index. The resulting arras has more rows/columns.

Replace array subset: Does nothing if the index is outside the array. Else it overwrites the selected row/column with new data. The array size remains constant (memory efficient!)

Built array: Appends a new row to the end (or prepends a new row to the beginning, depending on how it is wired). The new array will have one more row. No index needed.

 

And yes, you need to do something about all these race conditions in your final code. Currently, the outcome is not predictable.

0 Kudos
Message 5 of 7
(8,303 Views)

Thank you, I used the Built array function and got it working.

0 Kudos
Message 6 of 7
(8,262 Views)

Hi Rugan,

 

Please give kudos and mark a solution to let others know your problem is solved. Thank you

0 Kudos
Message 7 of 7
(8,250 Views)