07-19-2019 08:36 AM - edited 07-19-2019 08:38 AM
Hi all,
I'm having a weird problem when trying to add lines of 2D Array using a loop with shift register
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.
Solved! Go to Solution.
07-19-2019 09:00 AM
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.
07-19-2019 09:27 AM
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.
07-19-2019 09:36 AM
@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:
07-19-2019 02:47 PM
@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
07-19-2019 04:54 PM
Thank you Cy_Rybicki for pointing that out, an array of zeros work fine to me now. Much appreciated!
07-19-2019 04:59 PM - edited 07-19-2019 05:07 PM
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
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?
07-19-2019 05:20 PM - edited 07-20-2019 01:43 AM
@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.
07-22-2019 03:05 AM