Example Code

Insert 2D Array Data into an Existing 2D Array

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Download All

Description

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

  • LabVIEW Base Development System 2012 (or compatible)

 Hardware

  • No hardware required

 

Steps to Implement or Execute Code

  1. Download and open the attached file "Replace 2D Array LV2012 NIVerified.vi"
  2. Open VI and follow the instructions in Front Panel and Block Diagram and run the program.

 

Additional Information or References

Replace 2D Array_lv86.vi - Front Panel.png

 

Replace 2D Array_lv86.vi - Block Diagram.png

 

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

Comments
dsavir
Active Participant
Active Participant
on

exactly what I was looking for! Thank you so much!

"Wisdom comes from experience. Experience is often a result of lack of wisdom.”
― Terry Pratchett
Mads
Active Participant
Active Participant
on

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.