To download NI software, including the products shown below, visit ni.com/downloads.
Overview
This example demonstrates how to insert a 2D array into an existing 2D array by replacing existing values and adding missing values.
Description
LabVIEW Replace Array Subset function does not have the ability to insert a new array into an existing array that is smaller than the resulting array would be. For example if the original array has 2x2 values and another 2x2 values array should be replaced at row 1 and column 1, a 3x3 array would be the result. This example VI creates a new array with highest dimensions that are required (previously uninitialized values will be initialized and not lost).
Requirements
Software
Hardware
Steps to Implement or Execute Code
Additional Information or References
**The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
exactly what I was looking for! Thank you so much!
Just a couple of suggestions:
- Instead of using the Greater and Select functions in this case you can use the Max & Min function from the comparison palette. The Max output from this function is then the dimension(s) of the new array. However, it could be memory saving *not* to create a new array if the replacement will actually fit into the current array, so I would add a check on that and then skip the initialization of a new array if no expansion is needed.
- In cases where the replacement will expand the array it might be better to either offer the user of the code an input to set the default value, or change the initialization value from zero to "NaN". This might help identify cells that never have been filled by any inputs (neither the current array nor the elements to replace) in the later processing.