01-26-2012 10:38 AM
hello
i have the next code in labview which generates a random number between 0-100, i would like to do a counter which count each time that the random number is >50, but i don´t know how increase the times,i just see 1 when this happen,but if i have a new number >50 the counter is still 1, how could i increase the times that random number is >50? the case false is the same but i add +0, not +1 as true case
thanks
Solved! Go to Solution.
01-26-2012 10:58 AM - edited 01-26-2012 10:59 AM
You have the right idea with the shift register. But the shift register needs to be on the outer while loop. Connect the wire through the case structure in the false case. You don't need the inner for loop since it only executes one time. Also it is an initialized shift register since you have the zero wired to the left side. The result will always be 0+1. (Note, there is an increment function that you could use instead of adding 1)
01-26-2012 11:10 AM
sorry,i don´t understand what do you want to say with this: the shift register needs to be on the outer while loop?
01-26-2012 11:17 AM
Some times the feedback node can give a clean implementation since you do not have to pass the wires across the entire block diagram. Also the feedback node has a conditional terminal and initializer in place.
01-26-2012 11:23 AM
for example if i generate 10 random numbers,and there are 6 values >50 i want to see 6 in the output, but i just see 1
i want to accumulate the true case
01-26-2012 11:29 AM - edited 01-26-2012 11:35 AM
You can use a feedback node. That is a good way to do it but those can seem confusing to new users. They really are not complex but with inputs on the right it can seem strange.
See this example. The first loop shows what I was talking about with the shift register and case structure. You can also use the select function as shown in the second loop.
[Edit: I attached another method of incrementing using the bool to 0,1 function.
01-26-2012 11:50 AM
Thanks!!! it works well
03-24-2014 04:44 PM
I have tried both of the recommended schematics and I still get 0 and 1. Can anyone help me out. Maybe I am using a wrong function but I am not sure why it is not working properly.
Juan
03-24-2014 05:32 PM
jrod-
You have not tried the recommended schematics as they contain shift registers and your code does not. It is not the same code.
Read up about shift registers. Any introductory course explains them.
03-24-2014 08:02 PM
Thank you for the help, I understand what I did wrong. thanks again
Juan