Main Content

hasChanged

Detect change in data since last time step in Requirements Table block

Since R2022a

Description

example

tf = hasChanged(data) returns 1 (true) if the value of data at the beginning of the current time step is different from the value of data at the beginning of the previous time step. Otherwise, the operator returns 0 (false). Use this operator in the Requirements Table block.

Examples

expand all

Set the output data a to 1 if the input data M has changed since the last time step. Otherwise, set a to 0.

Requirements Table block that uses the hasChanged operator to determine the value of output data.

Set the output data a to 1 if the element in row 1 and column 3 of input data M has changed since the last time step. Otherwise, set a to 0.

Requirements Table block that uses the hasChanged operator to determine the value of output data.

Set the output data a to 1 if one of the fields of the structure struct has changed value since the last time step. Otherwise, set a to 0.

Requirements Table block that uses the hasChanged operator to determine the value of output data.

Set the output data a to 1 if the field struct.field has changed value since the last time step. Otherwise, set a to 0.

Requirements Table block that uses the hasChanged operator to determine the value of output data.

Input Arguments

expand all

Data defined in the Requirements Table block, specified as a:

  • Scalar

  • Matrix or an element of a matrix

  • Structure or a field in a structure

  • Valid combination of structure fields or matrix elements

See Define Data in Requirements Table Blocks.

If data is a matrix, the operator returns true when it detects a change in one of the elements of data. You can also index elements of a matrix by using numbers or expressions that evaluate to an integer.

If data is a structure, the operator returns true when it detects a change in one of the fields of data. You can also index fields in a structure by using dot notation.

You must specify an initial value for data. For more information, see Define Data in Requirements Table Blocks.

The argument data cannot be a nontrivial expression or a custom code variable.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | string | fi | enumerated | bus

Tips

  • If the Requirements Table block writes to the specified data but does not change the value, the hasChanged operator returns false.

Version History

Introduced in R2022a