Main Content

hasChangedTo

Detect change in data to specified value in Requirements Table block

Since R2022a

Description

example

tf = hasChangedTo(data,value) returns 1 (true) if the value of data is not equal to value at the beginning of the previous time step and is equal to value at the beginning of the current time step. Otherwise, the operator returns 0 (false). Use this operator in the Requirements Table block.

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

Examples

expand all

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

Requirements Table block that uses the hasChangedTo 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 to 1 since the last time step. Otherwise, set a to 0.

Requirements Table block that uses the hasChangedTo 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 and the current value of struct is equal to structValue. Otherwise, set a to 0.

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

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

Requirements Table block that uses the hasChangedTo 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 a 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

Value of the data at the current time step, specified as the same data type of data. value must be an expression that resolves to a value that is comparable with data:

  • If data is a scalar, then value must resolve to a scalar.

  • If data is a matrix, then value must resolve to a matrix with the same dimensions as data.

  • If data is a structure, then value must resolve to a structure whose field specification matches data exactly.

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 hasChangedTo operator returns false.

Version History

Introduced in R2022a