LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Repositioning elements in array to a new centre

Solved!
Go to solution

Hello,

 

I am having trouble figuring out how to find a solution to my problem here. I have found coordinates/indexes of the max value of my array and now I want to shift it to the centre/make it the new centre of the array (not sure how to do this for an even-sized array). After that, I want to create a circle around the max/centre value and make everything outside of the circle 0. Can anyone please help me with this problem or introduce to me some tools/VIs that may help me as I am still new to LV :). 

 

My current conceptual idea is to form the circle around the max value then retrieve that as a subarray and insert it into an initialised 0 array of the same size. But I am still lost on how to do this.

bche536_1-1610631793140.png

 

 

0 Kudos
Message 1 of 5
(161 Views)
Solution
Accepted by bche536

Initialize a new array of zeroes the same size as your current array.

 

Use array subset to get the section of the current array that you want.  Just do something math on the index you want to center up.  So a value's row and column, subtract 1 from each, put that into Array Subset with a length of 3 for row and column.

 

Now use Replace Array Subset on your newly initialized array starting at the row and column indices that are 1 less than its center.

Message 2 of 5
(121 Views)

Thanks this works!

 

 

0 Kudos
Message 3 of 5
(101 Views)

See also this recent thread, that includes more ideas and some code.

 

 

-Kevin P

0 Kudos
Message 4 of 5
(99 Views)

One thing you might have to pay special attention to is edge cases.  And this case, I literally mean "edge" case.   If the cell to center is at the edge of the array, you don't have any data off the edge of the array to select in your copy.  I don't know what you want the result to look like in that case.

 

And I don't know if the index handling would like working with negative indices and what you would get if you try to get a subarray starting at index (-1,-1)

0 Kudos
Message 5 of 5
(96 Views)