%% Example of Chart with Change Detection
% This model shows how the operators |hasChanged|, |hasChangedFrom|, and
% |hasChangedTo| detect specific changes in an input signal. In this
% example, a <docid:simulink_ref#f7-892016 Ramp> block sends a discrete,
% increasing time signal to a chart.

% Copyright 2018-2020 The MathWorks, Inc.

set_param(0,'ExportBackgroundColorMode','white')
model = 'sf_change_detection_ramp';
open_system(model)

%% 
% The model uses a fixed-step solver with a step size of 1. The signal
% increments by 1 every time step. The chart analyzes the input signal |u|
% for these changes:
%
% * Any change from the previous time step
% * A change to the value 3
% * A change from the value 3
%
% To check the signal, the chart calls three change detection operators in
% a transition action. The chart outputs the return values as |y1|, |y2|,
% and |y3|.

open_system('sf_change_detection_ramp/Chart')

%%
% During simulation, the <docid:simulink_ref#f5-1117037 Scope> block shows
% the input and output signals for the chart.
%
% * The value of |u| increases by 1 every time step.
% * The value of |y1| changes from 0 to 1 at time t = 1. The value of |y1|
% remains 1 because |u| continues to change at each subsequent time step.
% * The value of |y2| changes from 0 to 1 at time t = 4 when the value of
% |u| changes from 3 to 4. The value of |y2| returns to 0 after one time
% step.
% * The value of |y3| changes from 0 to 1 at time t = 3 when the value of
% |u| changes from 2 to 3. The value of |y3| returns to 0 after one time
% step.

sim(model);
open_system('sf_change_detection_ramp/Scope')