Showing results for 
Search instead for 
Did you mean: 

need help to find average value from input which varies with time

Go to solution

the purpose of this vi is to calculate the total average values from voltage inputs (that we generate from the sensors).

we face difficulty to get average value of the voltage. the value of the voltage is change with respect to time (in every seconds).

0 Kudos
Message 1 of 3
Accepted by topic author Submeet0490

Hi submeet,


On your VI:

uh-oh: heavy overuse of local variables! (Why are there 12 local variables of "x/y"?

Also: Cleanup your VI to get a better overview!

(You also forgot to attach the missing subVI.)

Why is "Table Control" a control when it is used as indicator?

Use arrays and polymorphic operations instead of duplicating code 12 times…

What's the purpose of that While loop to calculate "COFP Rate RT"? It's not needed…

Use array and loops instead of those >20 FormatIntoString functions on the right side of your loop!

Why is "FALL LEVEL" an integer when you want to assign float values?


On your question:

Your routine to calculate an average does exactly what you have programmed:

1. Create an array of 5 identical elements (with the very same value!)

2. Calculate the average of that array

Does it really make sense to calculate the average of 5 identical values?


When you need something different you need to program something different.

Sometimes it helps to develop an algorithm using a pen and a sheet of paper!

Best regards,

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 3

A lot of your code is highly flawed. Some has been mentioned, here's more:


  • I agree that you could reduce your code size to less that 5% using arrays and avoid all these duplicate operations. (Hey, it would fit on one screen, maybe even a postcard! :D) Your diagram is way too big for such little functionality. Even your fixed string arrays could be string array diagram constants.
  • The program will stop automatically once all code has completed. The "Abort" primitive at the end is completely pointless.
  • You can keep your xy graph data in a single 1D complex array directly connected to the graph terminal, dramatically simplifying the code. (xy graphs will plot IM vs RE of a complex array directly.)
  • If nobody ever clears your graphs and the timeout is set to a very large number, you will run out of memory eventually. (Please change the label of the cvlear button, not just the boolean text! "OK button" is not the right label to clear the graph!)
  • What does your mutilated express VI named "array seperate" do? Wouldn't "index array" work for that?
  •  For example your various small while loops have two initialized shift registers, but only run once. This means history values are never used and the shift registers AND loops are pointless.
  • You don't need separate numeric indicators for the slides, just make the digital display visible and move it in the desired place (50% fewer terminals on the diagram!). 
  • Instead of stopping the code after a certain time, create a state machine with an idle state so the experiment can be repeated without going to edit mode. Users of the program should not use the run button either.
  • You should use "build array" instead of "insert into array to build the table. If recording is off, you probably should not add elements.
  • Why did you decide to set the visa timeout to "4294967295"?? Seems a bit long.
  • Keep the front panel consistent. Don't mix modern, classic, and silver controls. Avoid overlapping elements.
  • ...
0 Kudos
Message 3 of 3