LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

3D Array: Can't replace subset 2D array?

Solved!
Go to solution

Hey guys,

I've discovered (possibly) a rather odd event. In debugging my code I came accross my Replace Array Subset function to find it was the source of my frustrations. Either I don't understand how it works for 3D arrays (I use it alot for 2D, 1D) or there is a bug. I've attached an image here of some example code. I cannot replace a 2D array within my 3D array. I'd like to take one page of the 3D and replace it with an updated/different page. The example image is of course only to highly the oddity.

 

Any thoughts?

0 Kudos
Message 1 of 9
(4,420 Views)

I'm guessing this is because in your example you are trying to replace a subset that doesn't exist in your input array. Even though your input array is 3 dimensions, it only has two elements in it. You are trying to replace those two elements with a 2D array that has four elements.

 

Eric

0 Kudos
Message 2 of 9
(4,409 Views)

I'm afraid thats not the case. Attached is the actual VI (2009), and another example with more entries in the first page.

Download All
0 Kudos
Message 3 of 9
(4,404 Views)
Solution
Accepted by topic author Maddox731

Regardless of the dimension of the input array, the result of Replace Array will never increase the number of elements.  You are trying to grab the first page, append a row, then replace the first page.  The result is that the replacement is cropped to the original size of the first page, so you have an elaborate NOP (no operation).  Switch the inputs of your top Build Array and see what happens. 

 

You can not replace an element which does not exist in the input array.

0 Kudos
Message 4 of 9
(4,399 Views)

Aha that makes alot of sense.

Thanks Darin. I'm so used to LabVIEW dynamically growing and shrinking my arrays I hadn't considered that Replace Array Subset won't allow alteration of the replaced subarray's number of elements.

 

Thanks again! I'll stick with Delete and Insert then as this will support the dynamic behavior I wanted.

0 Kudos
Message 5 of 9
(4,395 Views)

Be aware that deleting and inserting elements into an array is inherently slow and can fragment memory.  This only becomes a problem with larger arrays or highly repetitive operations.  For and example of this type of problem and alternatives, check out this thread.

0 Kudos
Message 6 of 9
(4,367 Views)

I'll have to read that thread later today when I have time.

 

Here's a thread from the last couple of days where I had a discussion with altenbach about something similar. He put together a nice example that continuously measures the time required to shift the elements of an array using different methods. It's towards the end as we had changed subjects from what was originally posted.

 

http://forums.ni.com/t5/LabVIEW/Log-Alarm-Only-Once/m-p/1511376#M565723

 

Eric

0 Kudos
Message 7 of 9
(4,363 Views)

Thanks for the link,

 

I figured delete and insert would be a performance hit compared to replace array subset, but I wanted my 3D array to grow and shrink dynamically, its the price you pay. Do you think I should instead initialze a very large empty 3D array, performance all the replace options and then have my code ignore entries that are empty? (Similar to the bucket brigade implementation)

 

 

0 Kudos
Message 8 of 9
(4,357 Views)

That approach would certainly speed things up, at the cost of an initial memory hit.  If you know your maximum memory usage and it is something you can live with, I would probably go with that approach.  Any time you can avoid hitting the memory manager, you will speed things up.

 

You may want to consider LabVIEW classes to handle managing the allocated vs. used data.

0 Kudos
Message 9 of 9
(4,340 Views)