LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to add the mutiple random number together ? The random numbers are generated out of the for loop .

1.jpgi want to add all the elements at the red arrow place . Thank you first 

0 Kudos
Message 1 of 12
(2,812 Views)

The 0 indicator can generate the elements one by one .  How to add all of them together ? Thank you 

0 Kudos
Message 2 of 12
(2,811 Views)

If English is not your native language try using Google Translate because I can not make sense of what your question may be.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 12
(2,782 Views)

I think I understand what you want to do.  Here's what I think:

  • The nested Case structure that has the element pointed to by the Red Arrow is inside two nested For Loops, both looping 8 times.
  • Each inner loop produces a Value (given the curious Label "0").  You want to either:
    • Sum each of the 8 values produced by the inner loop, or
    • Sum all 64 values produced by the inner and outer loops.

If this is what you want to do, the result is easy to obtain:

  1. Branch the wire going to the "0" indicator and run it to the edge of the inner For Loop.  It will create an Indexing Tunnel, which outputs a 1D array.
  2. Wire the output from this Tunnel (again, a 1D Array) to the Sum Array Values function on the Numeric Palette.
  3. If you want to sum all 64 values, simply wire the output of the Sum (which will just be a Dbl) to the outer For Loop, making a second Indexing Tunnel, and add a second Sum Array Values to sum this outer Array.

Bob Schor

0 Kudos
Message 4 of 12
(2,773 Views)

I should have asked -- did you wish to watch the sum accumulate, that is, did you want to have, inside the inner loop, a second indicator called, maybe, "Sum 0" that starts at 0, gets the first "0" value, adds the second value, the third value, etc. so you can see not only the "0" indicator change as the inner loop runs, but you can see the "Sum 0" indicator change?  The method I just explained does the summation after the loop exits, so you don't see the intermediate sums.

 

If you do want to see the sums accumulate, you can do that, as well.  A little more work:

  • Right-click the left edge of the inner For loop and insert a Shift Register.  Wire (from outside the Loop) a numeric Dbl of 0 to it.  This initializes the sum.
  • Inside your loop, wire an "Add" function to get the value going to Control "0" and a wire from the left Shift Register.  This adds the "0" value to the sum-so-far.  Wire the output of the Add to the right Shift Register.
  • I assume you know how Shift Registers work -- anything put into the right-hand register when a Loop ends will appear in the left-hand register when the Loop repeats.
  • The output from the right-hand Shift Register (when the Loop exits) will contain the sum of all 8 values.  Note it won't be updated until the loop ends -- if you want to watch it change, you need to place the indicater inside the Loop and look at the output from the Add function.

Bob Schor

0 Kudos
Message 5 of 12
(2,769 Views)

@Bob_Schor wrote:

I think I understand what you want to do.  Here's what I think:

  • ...

Bob Schor


If I had a penny for every word I have posted guessing at what I thought a person was asking only to find out latter that my efforts were for not...

 

Spoiler
I would be retiring before the end of the year. Smiley Frustrated

 

Hopefully you guessed right!

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 12
(2,764 Views)

Thank you so much for your advice . As u can tell i am not a native english speaker . I am still working at this . Thank you for your concerning again . 

0 Kudos
Message 7 of 12
(2,757 Views)

To help you out, this is an illustration (in "pictures") of the methods I was describing.  This is a LabVIEW Snippet, but even if you don't know how to use Snippets, it is simple enough that you should be able to copy it as LabVIEW code.

SumsSums

This is a For Loop (the Wait is so you can watch it run and actually see things happening) where (random) Data are being created and display (once a second) in the indicator Datum.  When the For Loop ends, all the Data (which have been brought out through an Indexing Tunnel) and summed and displayed as "Sum of Data".  The other method is shown below, starting with a Shift Register (initialized with 0) and used to compute a Running Sum.  When the Loop exits, Running Sum should equal Sum (since they both add up the same 8 numbers).

 

I hope this helps you out, and answers the question you were trying to ask.

 

Bob Schor

0 Kudos
Message 8 of 12
(2,744 Views)

Hi , thank you so much . basic on the picture . the "random data" is inside the for loop . And my question is what if the data is outside the loop ? 

because the problem i met  i dont know how to add it into the for loop  just like the “0” indicator in the picture . Thank you so much . and i try to describe all the details in another replying . 

0 Kudos
Message 9 of 12
(2,739 Views)

I am sorry i made it comlicated . i try to explain it . 

1.This is parts of the HOG . right now i can get two same size arrays . one of the array , every elements are from 0- 180 . and then classify them into 9 bins . 0-20 20-40 40-60 ....

2. About the other array , we do the calculation at the same position as the first array . such as : the first array the (0,0) is 25° . if the element at the same coordinate (0,0) of second array  is 60 . We calculate as following . distance to bin 20 and bin 40 are 5 and 15 degrees ,respectively . 

ratios are 15/20=3/4 ,5/20=1/4 .  So we vote the value   60 x 3/4 =45    to the  20 bin . and 60 x 1/4 = 15 to the 40 bin . 

3. then , suppose they are 8x8 arrays .  and we add every values after voting  together into the each bins .  

4 . after that making a histograph using the 9 bins values .  

 

the question is how to add each value together after calculation.  I hope it is a little clear . sorry for my limit english skill  and thank you for your help again . i really appreciate it . 

0 Kudos
Message 10 of 12
(2,734 Views)