06-10-2024 04:34 PM
My goal is to insert letter i into second row and fifth column. The insert into array is not really working for me.
Below is the result I want:
Below is how my code looks like:
Solved! Go to Solution.
06-10-2024 05:01 PM
You have a couple issues here. Consider how you might want this to work. You're inserting a 1D array (of 1 element) at the end of this array, so it puts it at the top. If you only have one element, how would LabVIEW know to put it at the bottom? It doesn't; it puts it at the top.
Also, LabVIEW arrays cannot have "null" elements. You start with a 2x4 array and add one element, so now it HAS to be a 2x5 array. What should go into that other spot?
If you don't specify an element (as you've done) it will automatically pad out the data with the default data type here, which is an empty string.
All you have to do is make the new array you insert into the array you actually want to insert, which includes an empty element before your "i":
Also, don't forget you're using Insert into Array, not Replace Array Element. "Insert" will make room for a new element by moving around other elements to make it fit. This means you MUST give it a 1D array, because how else would it know to make room?
Also, if you use Replace Array Element you will still need to pad your array, since Replace can't replace an element that isn't already there.
Hope that helps.
06-10-2024 08:48 PM - edited 06-13-2024 10:03 AM
Obviously, all rows must have the same number of elements, so instead of constantly growing your array whenever you try add something outside the current bounds, start with a 2D array that is sufficiently sized for the duration of the run. This is much more efficient, so if you think you'll eventually end up with a 10x10 array, why not initialize it as such??
Of course you can create your own "replace array element" that would automatically pad and resize as needed. You could even make it a vim. I am sure somebody already wrote that. I like performance and don't like to hammer the memory manager with menial tasks. Since arrays need to be contiguous in memory order, inserting a column requires a fresh allocation where all elements need to be moved to a new memory locations. Expensive!
See also our talk form many years ago (part II, slide 11) shown below:
06-11-2024 11:09 AM - edited 06-11-2024 11:16 AM
Thank you, BertMcMahan and Mr. Altenbach for sharing these great information and the codes! I'm also going to finish watching the talk form many years ago . I watched it a little bit and it's very informative.