Variables in Math Functions

Math functions support var & local variables

  • var declared variables keep their values between the calculation of one sample to the next. They are initialized once when evaluation the value of the first sample and can be used to “transfer” intermediate results to the next calculation cycle.
  • local declared variables are always initialized when calculating a sample. They can be used to calculate intermediate values – e.g., if an intermediate result is required multiple times in the same expression.

Example #1

Calculate the average wheel speed over a file

var wheelSpeedSum

var wheelSpeedCount

Local wheelSpeedAve := (vwheel_fl + vwheel_fr) / 2

wheelSpeedSum := wheelSpeedSum + wheelSpeedAve

wheelSpeedCount := wheelSpeedCount + 1

wheelSpeedSum / WheelSpeedCount

Example #2

You can even use script blocks within any other function argument. Simple put your expressions within “begin” and “end”

var wheelSpeedSum

var wheelSpeedCount

If (nmot >= 5000;

begin

Local wheelSpeedAve := (vwheel_fl + vwheel_fr) / 2

wheelSpeedSum := wheelSpeedSum + wheelSpeedAve

wheelSpeedCount := wheelSpeedCount + 1

end; 0)

wheelSpeedSum / WheelSpeedCount