MATLAB: How to set a change event (Implicit Event in Stateflow) to get triggered only when the value of a variable changes to a different one

haschangedstateflow

How can I set a change event (Implicit Event in Stateflow) to get triggered only when the value of a variable changes to a different one? Right now it gets triggered everytime the variable gets written to, even when the value remains the same.

Best Answer

You can use the hasChanged operator, which was introduced in Stateflow 7.0 (R2007b). If you are using a previous version, you would need to create a top-level parallel state which double buffers the data values and the actual check would be transformed to:
"data_prev != data_start"
The top-level parallel state would need to contain something like the following:
data_prev = data_start;
data_start = data;
Related Question