Detect change in data from specified value
tf = hasChangedFrom(
true) if the value of
data is equal to
value at the
beginning of the previous time step and is a different value at the beginning of the
current time step. Otherwise, the operator returns
Detect Change in Matrix
Transition out of state if the previous value of the matrix
M was equal to
matrixValue and any
M has changed value since the last time step
or input event.
Detect Change in Matrix Element
Transition out of state if the element in row 1 and column 3 of the matrix
M has changed from the value
since the last time step or input event.
In charts that use MATLAB® as the action language, use:
In charts that use C as the action language, use:
Detect Change in Structure
Transition out of state if the previous value of the structure
struct was equal to
and any field of
struct has changed value since the last
time step or input event.
Detect Change in Structure Field
Transition out of state if the field
changed from the value
5 since the last time step or
data — Data
scalar | matrix | structure | ...
Stateflow® data, specified as a:
Matrix or an element of a matrix
Structure or a field in a structure
Valid combination of structure fields or matrix elements
data is a matrix, the
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. See
Operations for Vectors and Matrices in Stateflow.
data is a structure, the
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. See Index and Assign Values to Stateflow Structures.
data cannot be
a nontrivial expression or a custom code variable.
Standalone charts in MATLAB do not support change detection on an element of a matrix or a field in a structure.
value — Value of data at previous time step
scalar | matrix | structure
Value of the data at previous time step, specified as the same data type
value must be an
expression that resolves to a value that is comparable with
datais a scalar, then
valuemust resolve to a scalar.
datais a matrix, then
valuemust resolve to a matrix with the same dimensions as
Alternatively, in a chart that uses C as the action language,
valuecan resolve to a scalar value. The chart uses scalar expansion to compare
datato a matrix whose elements are all equal to the value specified by
value. See Assign Values to All Elements of a Matrix.
datais a structure, then
valuemust resolve to a structure whose field specification matches
If multiple input events occur in the same time step, the
hasChangedFromoperator can detect changes in data value between input events.
If the chart writes to the data object but does not change the data value, the
The type of Stateflow chart determines the scope of the data supported by the change detection operators:
Standalone Stateflow charts in MATLAB:
In Simulink® models, charts that use MATLAB as the action language:
In Simulink models, charts that use C as the action language:
Data Store Memory
In a standalone chart in MATLAB, a change detection operator can detect changes in data specified in a call to the
stepfunction because these changes occur before the start of the current time step. For example, if
xis equal to zero, the expression
truewhen you execute the chart
chwith the command:In contrast, a change detection operator cannot detect changes in data caused by assignments in state or transition actions in the same time step. Instead, the operator detects the change in value at the start of the next time step.
In a chart in a Simulink model, if you enable the chart option Initialize Outputs Every Time Chart Wakes Up, using an output as the argument of the
hasChangedoperator always returns
false. For more information, see Initialize outputs every time chart wakes up.
When row-major array layout is enabled in charts that use
hasChangedFrom, code generation produces an error. Before generating code in charts that use
hasChangedFrom, enable column-major array layout. See Select Array Layout for Matrices in Generated Code.
Introduced in R2007a