LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Shift resister for Array - bug?

Solved!
Go to solution

Hi all, 
I'm having a weird problem when trying to add lines of 2D Array using a loop with shift register

shift resister Array bug.pngUntitled.png

In the end, Array 2 should be the sum of all subarray lines in Array, but the result is empty.

I've never encountered this kind of behavior before, please help!

Thank you in advance.

 

0 Kudos
Message 1 of 9
(450 Views)

You are initializing your shift register with an empty array and then trying to add to it, which will result in an empty array as you have seen. Either initialize your shift register with an array of zeros with the desired dimension size, or add a case structure to your for loop which passes the sub-array to the shift register rather than adding on the first iteration.

0 Kudos
Message 2 of 9
(425 Views)

When doing operations (such as Add) on an array, the smallest array size wins.  Since one of the inputs to Add has a size 0x0, the output will be 0x0.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 3 of 9
(409 Views)

@VD89410A wrote:

I've never encountered this kind of behavior before, please help!


It's the expected behavior. I've never not encountered this behavior.

 

Use a selector after the add (or a case structure). If i=0, wire the subarray, it it's not, wire the shift register + sub array.

 

Or initialize the array that goes into the shift register. You can even delete the first row from the input array before the for loop, and auto index the next rows to add to it:

Add rows.png

0 Kudos
Message 4 of 9
(400 Views)
Highlighted
Solution
Accepted by VD89410A

@VD89410A wrote:

Hi all, 
I'm having a weird problem when trying to add lines of 2D Array using a loop with shift register


Here is away to do without using shift registers

 

Sum without Shift Registers.png

Message 5 of 9
(342 Views)

Thank you Cy_Rybicki for pointing that out, an array of zeros work fine to me now. Much appreciated!

0 Kudos
Message 6 of 9
(308 Views)

Wow, thank you Jamiva!

I didn't know there exist an Add Array Elements Function 

I might saw it once before, but...this definitely alternatively solves my problem.

For some reason, I still don't quite understand how is your code even works Smiley Happy

Can you explain it a bit? Especially, why does the For loop not require Count (N) terminal and the Indexing tunnel behavior of how to pass value between iterations?

0 Kudos
Message 7 of 9
(302 Views)

@VD89410A wrote:

Can you explain it a bit? Especially, why does the For loop not require Count (N) terminal and the Indexing tunnel behavior of how to pass value between iterations?


Autoindexing are very basic features of LabVIEW, and if this is not clear, I strongly recommend that you do a few more tutorials before proceeding.

 

In a nutshell, an autoindexing input tunnel will execute once for each array element (1D array input) or row (2D array input) and so on for nD arrays. The iteration count of the FOR loop is fully defined by the array size and wiring N would be redundant (and could even be wrong). Similarly, an autoidexing output tunnel will generate an output array with one element for each iteration.


LabVIEW Champion Do more with less code and in less time
Message 8 of 9
(292 Views)

@jamiva wrote:

@VD89410A wrote:

Hi all, 
I'm having a weird problem when trying to add lines of 2D Array using a loop with shift register


Here is away to do without using shift registers


Duh. :facepalm:

0 Kudos
Message 9 of 9
(204 Views)