From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to replace a portion of array

Hi,

 

I want to do some operations to a portion of a large array.

 

I know two ways of doing it. First, by taking out the subarray and insert back into the main array. Another one is using the "in place element structure".

The structure typically gives better performance.

 

The portion is determined as in the attachment. I have not implement the diagram but the dummy output I want is as shown. The distance represent the number of elements from the center (including the center itself)

 

Could anyone suggest what is the best way of doing this (in diagram) such that it minimize memory and execution time (since my array is large and the application is targeted for real-time). FInally the modified subarray should be inserted back into the main array unless using the in place element structure. 

 

Thanks a lot for any input.

 

 

 

 

Download All
0 Kudos
Message 1 of 22
(3,505 Views)

I just manage to implement it. Attached are the VIs. Sorry for the messy wires. =P

 

If anyone has any idea on how to improve the execution time, memory and structure, please let me know. The array is large and operation may be much more than as shown in the program.

I have not manage to implement the solution using the in place element structure yet since it does not allow replacing array subset.

 

Download All
0 Kudos
Message 2 of 22
(3,461 Views)

Hi,

 

I admit I've no idea what you're trying to do and why, but here is your code implemented using an in place structure. If the Center coordinate is given in 0 based indexing (so that in a 3x3 array, the center would be (1,1)) this gives the same result as your code. As I've no idea what parameters to put in this could be way off, but the in place structures used might give you an idea. Note that in the inner in place structure the split dimension is 1, and in the outer the split dimension is 0 (right click->split dimension).

 

Good luck,

Danielle

 

"Wisdom comes from experience. Experience is often a result of lack of wisdom.”
― Terry Pratchett
0 Kudos
Message 3 of 22
(3,431 Views)

It can be enhanced certainly.

 

- avoid building case structures for easy operations. There is a trade off [time-wise] between building the case structure and calculating some extra values. Benchmarking needed.

- use the in-place structure as dsavir has suggested. I modified his, becuase it was not working for me, and I had to use a lot of "transposing 2D array". Again, benchmarking needed for your case.

 

Enhance readability by using proper representations (I32 vs DBL for indexes).

 

I think the distance from the center (DFC) should be redefined. It should be one less. Which elemenets are selected for 0 and 1, in your case? IMHO, DFC=0: a single element / no elements around, DFC=1: 3x3 elements,... You have DFC=2: 3x3 elements. DFC=0:??? I couldn't bare this so, I redefined it for me.

 

If you are keen on the best timing, you might want to benchmark the three suggestons archived and attached below. Let us know.

 

Cheers,

0 Kudos
Message 4 of 22
(3,411 Views)

Hi,

 

To avoid transpose arrays, change the split dimension in the in place element structure (right click->split dimension).

 

Thanks,

Danielle

"Wisdom comes from experience. Experience is often a result of lack of wisdom.”
― Terry Pratchett
Message 5 of 22
(3,406 Views)

Right. Never though of the "zero" in the icon. Thanks!

0 Kudos
Message 6 of 22
(3,404 Views)

@dsavir wrote:

 

To avoid transpose arrays, change the split dimension in the in place element structure (right click->split dimension).


Wow I did not know that, kudo'd.  Still I've heard the transpose is like a no-op more or less.  Also why doesn't the primative split array support this feature?

0 Kudos
Message 7 of 22
(3,375 Views)

@Hooovahh wrote:

Also why doesn't the primative split array support this feature?


The primitive works only for a 1D array, doesn't it?

0 Kudos
Message 8 of 22
(3,368 Views)

@ghighuphu wrote:

The primitive works only for a 1D array, doesn't it?


Right...but why should it be limited in such a way, if the IPE structure isn't held to the same limitations?

Message 9 of 22
(3,361 Views)
I'll support the idea.
0 Kudos
Message 10 of 22
(3,358 Views)