LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

averaging each element of an array everytime it runs and plot it everytime

Solved!
Go to solution

HI,

I am trying to write a labview program where i can average each element of an array to the same array array element from previous iteration and plot it . I am stuck and need some help. For example, i will have {1,2,3} as an array from first iteration and i will plot each one separately. Then for second iteration i want average of 1 with new number, 2 with new element in array and so on and plot each one separately. Is this possible?

0 Kudos
Message 1 of 6
(1,092 Views)

Of course it is easily possible to do!

 

Keep adding each new array to the previous sum in a shift register (initialized with a correctly sized array containing all zeroes). To display the average, divide the sum by the number of additions.

0 Kudos
Message 2 of 6
(1,046 Views)

I tried initialization but I am not getting the sum. 

0 Kudos
Message 3 of 6
(1,017 Views)

Attach what you have so we can tell what's wrong. Did you initialize with an array of zeroes of the correct length or with an empty array by mistake?

0 Kudos
Message 4 of 6
(1,011 Views)

I have an array with 1 row and 2 column i.e. 2 elements for the first iteration and then i want to sum it with the elements from next iteration

0 Kudos
Message 5 of 6
(1,007 Views)
Solution
Accepted by topic author physikstar

You are not attaching any code (the VI!), just truncated ambiguous pictures. Delete the FOR loop and place the shift register on the toplevel loop (or use a feedback node with the initializer anchored on the outermost loop). Since you want to add the entire 1D array, autoindexing makes no sense here. At the same time, eliminate all your local variables, there are way too many race conditions (e.g. why do you think you need to read your same locals twice in parallel??). Where are their terminals? Why do you think you need a stacked sequence at all? There is a ">0" primitive or you can just wire the iterger to the case structure, making one case default and the other "1..".. If you would use "high resolution relative seconds" instead of the ticker, you would not need to divide by 1000.

 

There are a lot of other very questionable things, for example it makes no sense to recalculate the multiplier with every iteration. The multiplier is per axis, not per datapoint!

0 Kudos
Message 6 of 6
(989 Views)