To download NI software, including the products shown below, visit ni.com/downloads.
Overview:
This function inserts or replaces an element at any index within an array. If the requested index is valid and already exists within the array, the new element will be inserted or replaced into the array. If the index is larger than the size of the array, the array will be padded, and the new element will be appended at the requested position. This VI may be modified to work with different data types as well as inserting a subarray rather than just a single element.
Description:
First, the function compares the requested index position with the array size to determine whether an element already exists at this position or if the array needs to be resized. The user can select to replace or insert at the specified index if it exists. If it does not, the code uses the Reshape Array function to increase the size of the array, then places the element at the specified index.
This function allows you to avoid adding additional logic each time you manipulate an array and wish to avoid an array index out of bounds error. It is also useful for allowing reuse to insert, replace, or grow an array without additional coding necessary. This function could easily be modified to work with other data types.
Requirements:
Steps to Implement or Execute Code
Additional Information or References
Front Panel

VI Snippet
10-31-2010: Modified by CA for better inplaceness and simpler code. (reshape array replaces initialize array, two built array nodes and associated math)
**This document has been updated to meet the current required format for the NI Code Exchange. For more details visit this discussion threadhttps://decibel.ni.com/content/thread/15639**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
Are there any existing shipping examples in the LabVIEW Help that show this functionality? If so, please include some links. If not, we need to find out how to point the product to examples like these. Let me know.
If it's so darn easy to resize an array, why in the heck is there not an "autogrow" boolean property of arrays built right into LabVIEW? This would give the developer the choice of allowing the array to grow in demand for an index out of bounds inserts, while preserving the (safer default) character of not inserting into out of bounds locations.
Is there any way to find out how labview implements arrays under the hood? I spent all day trying to simply insert a new element into a 2 dimensional array at location (i,j).
Like this:
array
Simply can't do it with "insert element into array" You have to insert an entire new array into row i.
I ended up writing "InsertElementByRow" and "InsertElementByCol" Where I extract an entire row, replace the single element in that row, then put the row back, or, extract an entire column, (as a 1 dimensional array), replace that element, then replace the entire column.
But "replace array subset" works for an individual element. I'd like to understand why that is the case.
2D arrays much be rectangular, meaning that every row must have the same number of items in it. So it is obvious then that you can't just add a single element into a specific location unless you add an entire row.