Find abrupt changes in data
Create a vector of noisy data, and compute the abrupt changes in the mean of the data.
A = [ones(1,5) 25*ones(1,5) 50*ones(1,5)] + rand(1,15); TF = ischange(A)
TF = 1x15 logical array 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0
To compute the mean of the data in between change points, specify a second output argument.
[TF,S1] = ischange(A); plot(A,'*') hold on stairs(S1) legend('Data','Segment Mean','Location','NW')
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);
Compute abrupt changes in the mean for each row of a matrix.
A = diag(25*ones(5,1)) + rand(5,5)
A = 5×5 25.8147 0.0975 0.1576 0.1419 0.6557 0.9058 25.2785 0.9706 0.4218 0.0357 0.1270 0.5469 25.9572 0.9157 0.8491 0.9134 0.9575 0.4854 25.7922 0.9340 0.6324 0.9649 0.8003 0.9595 25.6787
TF = ischange(A,2)
TF = 5x5 logical array 0 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1
A— Input data
Input data, specified as a vector, matrix, multidimensional array, table, or timetable.
method— Change detection method
Change detection method, specified as one of the following:
'mean' — Find abrupt changes in the mean of
'variance' — Find abrupt changes in the
variance of the data.
'linear' — Find abrupt changes in the slope
and intercept of the data.
dim— Operating dimension
Operating dimension, specified as a positive integer scalar. By default,
ischange operates along the first dimension whose
size does not equal 1.
For example, if
A is a matrix, then
ischange(A,1) operates along the rows of
A, computing change points for each column.
ischange(A,2) operates along the columns of
A, computing change points for each row.
comma-separated pairs of
the argument name and
Value is the corresponding value.
Name must appear inside quotes. You can specify several name and value
pair arguments in any order as
TF = ischange(A,'MaxNumChanges',5)
'SamplePoints'— Sample points
Sample points, specified as the comma-separated pair consisting of
'SamplePoints' and a vector. The sample points
represent the x-axis locations of the data in
A, and must be sorted and contain unique
elements. Sample points do not need to be uniformly sampled. The default
sample points vector is
[1 2 3 ...].
This name-value pair is not supported when the input data is a
timetable. Timetables always use the vector of row times as the sample points. To use different sample points, you must edit the timetable so that the row times contain the desired sample points.
ischange([1 2 3 4 5 6],'linear','SamplePoints',[1 2 3
10 20 30])
'DataVariables'— Table variables to operate on
Table variables to operate on, specified as the comma-separated pair
'DataVariables' and one of the options
in this table. The
'DataVariables' value indicates
which variables of the input table to examine for change points. The
data type associated with the indicated variables must be
variables in the table not specified by
'DataVariables' are not operated on, so the
false values for those
A character vector or scalar string specifying a single table variable name
|Vector of variable names|
A cell array of character vectors or string array where each element is a table variable name
|Scalar or vector of variable indices|
A scalar or vector of table variable indices
A logical vector whose elements each correspond to a table variable, where
A function handle that takes a table variable as input and returns a logical scalar
A table subscript generated by the
'Threshold'— Change point threshold
Change point threshold, specified as the comma-separated pair
'Threshold' and a nonnegative scalar.
Increasing the threshold greater than 1 produces fewer change
The threshold value defines the number of detected change points and
cannot be specified when
'MaxNumChanges'— Maximum number of change points
Maximum number of change points to detect, specified as the
comma-separated pair consisting of
and a positive integer scalar.
ischange uses an
automatic threshold that computes no more than the specified value of
change points, thus
'Threshold' cannot be specified
'MaxNumChanges' is specified.
TF— Change point indicator
Change point indicator, returned as a vector, matrix, or multidimensional
TF is the same size as
S1— Mean or slope
Mean or slope of data between change points, returned as a vector, matrix, multidimensional array, table, or timetable.
If the change point detection method is
S1 contains the mean for each
If the method is
S1 contains the slope for each
s1 has the same type is the input data.
S2— Variance or intercept
Variance or intercept of data between change points, returned as a vector, matrix, multidimensional array, table, or timetable.
If the change point detection method is
S2 contains the variance for each
If the method is
S2 contains the intercept for each
s2 has the same type is the input data.
A vector of data A contains a change point if it can be split into two segments A1 and A2 such that
is the threshold value specified by the
'Threshold' parameter, and C represents a
For example, the cost function for detecting abrupt changes in the mean is , where N is the number of elements in a vector x. The cost function measures how well a segment is approximated by its mean.
ischange iteratively minimizes the sum of the cost functions to
determine the number of change points k and their locations such
 Killick R., P. Fearnhead, and I.A. Eckley. "Optimal detection of changepoints with a linear computational cost." Journal of the American Statistical Association. Vol. 107, Number 500, 2012, pp.1590-1598.
Usage notes and limitations:
For single-precision inputs, the output of the generated code might
not match the MATLAB® output. This is because the generated code for
ischange executes most intermediate computations
in single precision.
DataVariables must not contain duplicate variable