07-21-2023 08:50 AM
Hello,
I have been having a head scracher while using shift registers. When it is like shown in red on the picture (without any constant "0") it works as intended but the size of the output array just adds up every run and I do not want that. But when any constant are given to the shift register input, the outputs are just empty arrays and i do not understand why. I have changed and played around the part shown in green and when constants are given to "N" numbers of the loops the output are not empty but the loops dose not work as intended anymore. If anyone is instrested the way it should work:
Outer Loop: j=1;j++;j=Kal.
Inner Loop: i=j+1,i++,i=Kal.
Inside Inner Loop: Kj-Ki
Due to the input array having multiple colums that need to be read during loops the counters are slightly different. I have attached LV2016 version and not older because they were breaking while saving if so. I hope my question is somewhate clear, if not please let me know and Ill try my best to explain.
Looking forward for some answers, cheers,
Diural
Solved! Go to Solution.
07-21-2023 09:03 AM - edited 07-21-2023 09:13 AM
Fun fact about For Loops and Shift Registers:
If a For loop iterates 0 times the SR value In is absolutely ignored and the output is the default value.for the datatype. That gets even more complicated when you use uninitialized shift registers since, the default data value is retained for the next execution.
Just like you just proved for yourself with your example!
What you probably should be doing is; transpose the 2D array out of read from xxxx (that function did not exist in that form prior to 2016 and won't backsave to 2015) Then AUTO index the nested For Loops over the array. Don't wire anything to the N terminals and you will solve your issues
07-21-2023 09:06 AM
So it can be solved by never iterating the loop"0" times and stoping when it gets to 1 ?
07-21-2023 09:15 AM
@Diural wrote:
So it can be solved by never iterating the loop"0" times and stoping when it gets to 1 ?
I just edited my reply above with suggestions after inspection of you code.
07-21-2023 02:03 PM - edited 07-21-2023 02:04 PM
@JÞB wrote:
Fun fact about For Loops and Shift Registers:
If a For loop iterates 0 times the SR value In is absolutely ignored and the output is the default value.for the datatype. That gets even more complicated when you use uninitialized shift registers since, the default data value is retained for the next execution.
Just like you just proved for yourself with your example!
What you probably should be doing is; transpose the 2D array out of read from xxxx (that function did not exist in that form prior to 2016 and won't backsave to 2015) Then AUTO index the nested For Loops over the array. Don't wire anything to the N terminals and you will solve your issues
I believe you misspoke. I'm pretty sure that the behavior is exactly the opposite of what you mentioned. I believe that if you don't have a shift register - and just a tunnel - what you decribed above happens. I believe that the way to mitigate what you described above is to use a shift register. That way, whatever is at the input of the shift register appears at the other side of the FOR loop in case of zero iterations.
07-21-2023 06:35 PM
@billko wrote:
@JÞB wrote:
Fun fact about For Loops and Shift Registers:
If a For loop iterates 0 times the SR value In is absolutely ignored and the output is the default value.for the datatype. That gets even more complicated when you use uninitialized shift registers since, the default data value is retained for the next execution.
Just like you just proved for yourself with your example!
What you probably should be doing is; transpose the 2D array out of read from xxxx (that function did not exist in that form prior to 2016 and won't backsave to 2015) Then AUTO index the nested For Loops over the array. Don't wire anything to the N terminals and you will solve your issues
I believe you misspoke. I'm pretty sure that the behavior is exactly the opposite of what you mentioned. I believe that if you don't have a shift register - and just a tunnel - what you decribed above happens. I believe that the way to mitigate what you described above is to use a shift register. That way, whatever is at the input of the shift register appears at the other side of the FOR loop in case of zero iterations.
That is correct. If a loop iterates 0 times, outputs of shift registers will be whatever is at the input; outputs of tunnels will be the default for the data type.
07-22-2023 12:27 AM
@paul_a_cardinale wrote:
@billko wrote:
@JÞB wrote:
Fun fact about For Loops and Shift Registers:
If a For loop iterates 0 times the SR value In is absolutely ignored and the output is the default value.for the datatype. That gets even more complicated when you use uninitialized shift registers since, the default data value is retained for the next execution.
Just like you just proved for yourself with your example!
What you probably should be doing is; transpose the 2D array out of read from xxxx (that function did not exist in that form prior to 2016 and won't backsave to 2015) Then AUTO index the nested For Loops over the array. Don't wire anything to the N terminals and you will solve your issues
I believe you misspoke. I'm pretty sure that the behavior is exactly the opposite of what you mentioned. I believe that if you don't have a shift register - and just a tunnel - what you decribed above happens. I believe that the way to mitigate what you described above is to use a shift register. That way, whatever is at the input of the shift register appears at the other side of the FOR loop in case of zero iterations.
That is correct. If a loop iterates 0 times, outputs of shift registers will be whatever is at the input; outputs of tunnels will be the default for the data type.
I believe this to be a "brain fart". 😄
07-22-2023 04:22 AM - edited 07-22-2023 04:23 AM
Hi eeryone,
After quite a bit of forum surfing and labview clicking I have come up with a solution. As stated by your answers having "0" go into the loop's iteration "N"umber it did not work at all so I have changed the algorithm to: (changing the green part of the block diagram)
L1 j=1;j++;N=Kal-1
L2 i=j;i++,N=Kal-j
K(j)-K(i+1)
I still did not get what I wanted after I made the block diagram easier (red part) so I found out that even though the inner loop was working as intended thanks to the shift register, it was in repeat due to the outer loop, thus creating another shift register in the outer loop took care of that. As a result I got the "outer loop 2d array", but again this was not want i wanted (blue part). Finally I have cleaned the "empty" parts of the array (yellow part) and as a result I got "cleaned 1d array" part.
Cheers,
Diural
07-22-2023 05:00 AM - edited 07-22-2023 07:00 AM
Your code is incredibly convoluted and you don't need any shift registers at all.
see if the attached can give you some ideas.
Since we no longer create padding, the parts after the loop are probably not even needed. It could be useful if you want to eliminate exactly one element, e.g. "K1 - K4".
07-22-2023 05:46 AM
@altenbach wrote:
Your code is incredibly convoluted and you don't need any shift registers at all.
Compared to what some of my former cow-orkers were able to do, I would peg Diural's code as only moderately convoluted.