LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace array subset (String)

Hello all,

 

I am trying to add 2 string elements to a 2D array at a specific location (row 1, column 2) and (row 1, column 3).

Since I need to specify both row and column in the index, I know I can't use "Insert Into Array". Instead, I am using "Replace Array Subset", but it isn't "replacing" the empty array values with the strings I am giving it. (See below, desired values are in red.)

 

table.JPG

 

 

Please see attached code snippet.

0 Kudos
Message 1 of 4
(3,676 Views)

The original array needs to be large enough to hold the new elements, and in your case it is not.  Replace array subset will not insert elements that are outside the bounds of the original array.  Start with a 4x3 array, even if some of the string elements are empty strings.

0 Kudos
Message 2 of 4
(3,670 Views)

Ahhh! That's completely obvious in hindsight. Another question then, how can I programmatically start off with a 4 by 3 array?

If this makes a difference- I started with an array constant to illustrate the array for you in the simplest way possible, in my actual VI I built the array using acquired values.

 

I don't want to have to manually initialize each cell that I need to fill.

Laura

0 Kudos
Message 3 of 4
(3,661 Views)

Laura,

 

You can create an array of any size using the Initialize Array function.  Expand it for 2D.  Of course this will have all the values the same.

 

How you can set the values programmatically depends on where you get the data.  For 4x3 it is probably faster to create the array constant than to write a program to Replace Array values.  If the data is in a spreadsheet file, the Read From Spreadsheet File function with the data type set to string should work.

 

Your image appears to show arrays with some rows having different lengths.  That is not allowed in LV.  Putting in the 2192 and 2001 will make all rows have 4 columns.  Rows are listed first so you have a 3 (row) X 4 (column) array, not 4x3.

 

Lynn

0 Kudos
Message 4 of 4
(3,651 Views)