%% Change in Linear Regime
% Create a vector of noisy data, and compute abrupt changes in the slope and intercept of the data. Setting a large detection threshold reduces the number of change points detected due to noise.

A = [zeros(1,100) 1:100 99:-1:50  50*ones(1,250)] + 10*rand(1,500);
[TF,S1,S2] = ischange(A,'linear','Threshold',200);
segline = S1.*(1:500) + S2;
plot(1:500,A,1:500,segline)              
legend('Data','Linear Regime')

% As an alternative to providing a threshold value, you also can specify the maximum number of change points to detect.

[TF,S1,S2] = ischange(A,'linear','MaxNumChanges',3);

% Copyright 2019 The MathWorks, Inc.