SampleAndHold('Expression','Sample','Initial=0)

Arguments

'Expression'

Measured value

'Sample'

Parameter that determines whether the function follows the measured value (1) or holds the last measured value (0). 'Sample' can be a condition itself or be determined by a different function.

'Initial'

Optional parameter (default = 0), which determines the initial value of the function when 'Sample' is inactive at the start of the measurement.

Description

This function is a sample-hold function. The output follows 'Expression' when 'Sample' = TRUE. It remains unchanged when 'Sample' = FALSE. With the optional 'Initial' parameter, the initial value of the output can be specified if the function is on "Hold" when called.

Example

The function should follow a measured value if it is positive and be held as soon as the measured value becomes negative.

Task description

An If query as the 'Sample' parameter returns the value 1 for positive values and the value 0 for negative values.

Solution

In the figure below the blue curve shows the measured value and the red curve shows the output value with held measured values.