03-31-2016 06:01 AM
Hi,
My problem:
I have a 2D array of dimension 3x3. I want to insert this array into a bigger array of dimension 5x5 (having all elements zero, say) at alternate positions.
More clearly,
My 3x3 array is suppose: [1 2 3
4 5 6
7 8 9]
My final array (5x5 array) should look: [1 0 2 0 3
0 0 0 0 0
4 0 5 0 6
0 0 0 0 0
7 0 8 0 9]
I will be very grateful, if somebody helps me in this regard.
Thanking You!
03-31-2016 06:37 AM
Maybe this help you
03-31-2016 09:39 AM
Think like a mathematician and solve an easier problem.
Consider a 1D array, [1 2 3] that you want to transform into another 1D array, [1 0 2 0 3]. Here is an easier problem -- transform the [1 2 3] array into [1 0 2 0 3 0] (a simple FOR loop where you replace a single element with a 2-element 1D array, [x 0], and use a concatenating output tunnel does the trick). Now just delete the last element!
Now that we have solved the 1D problem, extend it to a 2D problem. The inner loop creates a single row (of either 5 or 6 elements), and the outer loop assembles the rows into a 2D array by appending a row of zeros to each single row and outputting through a concatenating tunnel. You then trim the final (zero) row and possibly the final column if you didn't do in "inside the loop".
The other suggestion here will probably work (I didn't test it, but assume it wouldn't have been posted if it didn't work). However, just looking at it, I couldn't easily see what it was doing, so have to "take it on faith" that it works. My algorithm, particularly with a comment or two, should be "obviously correct" to someone who knows a little LabVIEW.
Bob "Do the Math" Schor
Bob Schor
03-31-2016 10:26 AM
What about stupid replace at index x 2?
No big array resizing multiple times.
03-31-2016 12:10 PM
03-31-2016 04:01 PM
Yep, the Alexander/Ben "direct" method is probably optimal ...
Bob Schor