Main Content

getPrevious, prev

Previous value of data

Description

example

z = getPrevious(u) returns the value of the data at the previous time step. This operator works only in the Requirements Table block.

z = prev(u) is an alternative way to execute getPrevious(u).

Input Arguments

expand all

Data, specified as data defined in the Requirements Table block. See Define Data in Requirements Table Blocks. u must be specified as input or output data.

Output Arguments

expand all

Value at the previous time step, returned as a value with the same data type of u.

Examples

expand all

At the start time, set y equal to 0. After the start time, recall the value of the input data u in the precondition at the previous time step. One requirement checks if the previous value of u is greater than or equal to the current value, and another checks if the previous value is less than the current value. The block assigns different values for the output data y.

This image shows a Requirements table that changes the output action depending on the previous value of the block input. If the block input previous value is greater than or equal to the current value, the block outputs 1. Otherwise, the block outputs 2. At the start time, the block outputs 0.

Tips

  • If getPrevious attempts to return the value of the data at a time step when it was not defined, it returns an undefined value. For example, data is not defined before the simulation time is 0. For this situation, use the isStartup operator to define additional requirements at a simulation time of 0 and ~isStartup at the other time steps.

  • You can use this operator only in the Requirements tab.

Version History

Introduced in R2022a