MATLAB Answers

Using controlchart with specified time vector

3 views (last 30 days)
KAE on 3 Aug 2020
Edited: KAE on 3 Aug 2020
I have some measurements consisting of an irregularly-sampled datetime vector and measured values, and I would like to use the controlchart function to make an "individual observeration" plot of this data. How can I create the time vector that controlchart will accept? The input argument can be a time series object but I am not sure how to create one from my datetime vector. [I am also curious about the history of the time series object since the documentation for it is buried - was this a brief-lived predecessor to the datetime type?]

Answers (1)

KAE on 3 Aug 2020
Edited: KAE on 3 Aug 2020
Here is what I have tried. The time labeling on the x-axis is not as nice as plots that use datetime; for my real data, it is labeled in financial quarters (!), but this can be changed.
% Create example datetime vector of measurement times
t1 = datetime(2000,1,1,1,0,0);
t2 = datetime(2001,12,31,0,0,0);
timeDatetime = t1:t2; % Format is 'dd-MMM-uuuu HH:mm:ss'
% Convert from datetime to cell array of time strings
timeForSeries = cellstr(timeDatetime);
nTime = length(timeForSeries);
% Create fake measurements which have a Gaussian distribution
% since this is what controlchart assumes
mu = 5; sigma = 7; % Mean and standard deviation of distribution
valuesForSeries = normrnd(mu,sigma,[nTime 1]);
% Make timeseries object
ts = timeseries(valuesForSeries, timeForSeries);
controlchart(ts, 'chart', 'i'); % Individual measurement

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!