11-16-2020 06:11 PM
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?
Solved! Go to Solution.
11-16-2020 10:42 PM
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.
11-17-2020 03:05 PM
I tried initialization but I am not getting the sum.
11-17-2020 03:40 PM - edited 11-17-2020 03:41 PM
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?
11-17-2020 03:52 PM
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
11-17-2020 06:20 PM - edited 11-17-2020 06:25 PM
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!