LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Shift 2D Array circularly in labview

Solved!
Go to solution

@Bart_Boshuizen wrote:

Bart_Boshuizen_0-1753471662979.png

I was looking for a solution.. I came up with this. Can't be much simpler than this I guess.


 

This is a "solution" to a very different problem, because you don't have inputs for row# and col#.

 

It is also a bad example because not all elements have a unique value and it is thus impossible from the output to tell e.g. which of the four "2" ended up where. Your code is also not scalable, because all blue constants needs to be edited whenever the size changes. Correct would be to derive their value from the input array size.

 

0 Kudos
Message 11 of 15
(210 Views)

Glad you see as a problem as well.

It was a quick and dirty solution for the rotation of a row aka shift circularly. Of course you can replace the '20' with the result of the multiplication of row and column size, hence the comment above the array. Of course you can use the actual row size (both positive or negative are possible). And finally of course you can use the original array dimensions to reshape the array back to the original.

Here is the use case:

sample add new data at end.png

Bart Boshuizen,
www.morechemistry.com
0 Kudos
Message 12 of 15
(192 Views)

Yes your earlier code could look as follows:

altenbach_0-1753717527980.png

 

You are adding a new problem where you then replace the last row, which is probably one typical use case for a fixed size 2D FIFO. (Rotate and replace oldest row)

 

Still, both reshape operations show a potential buffer allocation and I am somewhat suspicious about performance. There are probably ways for better inplaceness, but I have not tested how smart the compiler can deal with your version. 😄

 

In some scenarios (e.g. if reading out is much rarer than replacing rows) one could just replace the oldest row in place, keeping track of the insert point and only reshuffle when needed.

0 Kudos
Message 13 of 15
(173 Views)

If the only target is to minimize diagram size, here's one possibility (bottom).

 

altenbach_1-1753719419121.png

 

Still, I would probably use a bit more code for better inplaceness.

 

 

 

 

0 Kudos
Message 14 of 15
(170 Views)

The came up with my "solution' so I could avoid using the build array function, because I remember there is some issue with memory buffers being used. (In the application I keep track of data in an array, with 3600 rows and a limited number of columns, which is prefilled with NaNs. I've also considered a pointer for row replacements, but the presented method (itself) is way faster than I need.)

 

I like the multiply array elements function! Nice!

 

Bart Boshuizen,
www.morechemistry.com
0 Kudos
Message 15 of 15
(164 Views)