
control chart on new data
8 views (last 30 days)
Show older comments
Assume that I have historic data and I calculated the LCL and UCL and CL. I have now new data and I need to check it with these locked values. How I can plot a control chart without recalculating LCL and UCL and CL when I had new data. Thank you .
0 Comments
Answers (2)
dpb
on 1 Oct 2017
Edited: dpb
on 1 Oct 2017
A control chart plot is just a line plot with specific values...you can add to it just like any other plot by setting hold on and adding whatever additional data you want. I'll illustrate using the example 'xbar' chart in the doc--
Start with the original --
>> load parts % loads an array runout
>> [st,pl1]=controlchart(runout,'chart','xbar') % make an xbar chart, look at the results
st =
mean: [36x1 double]
std: [36x1 double]
n: [36x1 double]
range: [36x1 double]
mu: -0.0864
sigma: 0.1302
pl1 =
pts: [36x1 double]
cl: [36x1 double]
lcl: [36x1 double]
ucl: [36x1 double]
se: [36x1 double]
n: [36x1 double]
ooc: [36x1 logical]
>> hold on
There's your historic data, now let's explore how the plot was constructed. We know lines are children of axes, so...
>> hAx=gca; % get the current axes handle to a variable
>> get(hAx,'children') % and the handles of objects that were drawn
ans =
5x1 graphics array:
Line
Line (lclucl)
Line (cl)
Line (ooc)
Line (pts)
>>
Ah! That's handy, not only are the lines there as we knew had to be, they added identifying labels via the 'tag' property so we can find ones we need/want easily --
>> hL_UCLC=findobj(hLCC,'tag','lclucl') % find upper/lower CL handle and save for later
hL_UCLC =
Line (lclucl) with properties:
Color: [1 0 0]
LineStyle: '-'
LineWidth: 0.5000
Marker: 'none'
MarkerSize: 6
MarkerFaceColor: 'none'
XData: [0.5000 36.5000 NaN 0.5000 36.5000]
YData: [-0.2817 -0.2817 NaN 0.1089 0.1089]
ZData: [1x0 double]
Show all properties
>> hL_CL=findobj(hLCC,'tag','cl') % and same for the center line...
hL_CL =
Line (cl) with properties:
Color: [0 0.7500 0]
LineStyle: '-'
LineWidth: 0.5000
Marker: 'none'
MarkerSize: 6
MarkerFaceColor: 'none'
XData: [0.5000 36.5000]
YData: [-0.0864 -0.0864]
ZData: [1x0 double]
Show all properties
>>
OK, now we see how the control lines were drawn; the UCL/LCL are one line but they used the "trick" of embedding two lines in a single vector by the NaN entry in the middle. The centerline is just a single line so it's only two points. What we'll want to do is just lengthen those lines by adjusting the 'XData' value for the right ends once we've got the additional data to plot.
So now let's build some new data to add to the plot without recomputing control limits...
L=length(runout); % the length of current data array for beginning location of new
N=10; % how many points to add
xAdd=[L:L+N].'; % the new data x values to add; start at the end to not have break
ro=(rand(N,1)-0.5)/2; % new sample data of roughly right mean/variation to match runout
ro=ro*st.sigma/std(ro); % scale the std to actually match
ro=[st.mean(end);ro]; % and put the last observed data value as initial value
OK, that's built some data to add to the plot that starts with the last previously observed location and value and adds an additional N points to it. NB: I fixed range to match but the mean of original is somewhat negative so there's an offset of the new from the old to the positive--that might be a typical thing that happens in reality; here it's immaterial as all we're doing is illustrating the mechanics of manipulating the existing plot.
hLAdd=line(xAdd,ro,'linestyle','-','marker','x','color','b'); % new line with different marker
hL_UCLC.Xdata([2 5])=L+N+0.5; % adjust the RH UCLC line X to new length overall plus 0.5
hL_CL.XData(2)=L+N+0.5; % and same thing for the centerline
xlim([0 L+N]+0.5) % and set the axes x limits to span the new x
The above leaves the following plot --

where the new data are shown with the 'x' marker and the chart control lines are just extended by resetting their existing 'XData' properties to match the additional number of points.
The above is done for a new batch of data; it could just as easily be done on a point-by-point basis by adding new data to the new line handle. The "tricks" for doing this are basically those shown in the section on 'Animation' in the graphics help section although essentially all the secrets have been revealed here--update the existing data arrays inside the plot instead of adding more lines or redrawing the whole thing every update cycle.
You could, of course, update the legend to label new data as well; left as "exercise for the student" :)
A worthwhile enhancement request would seem to be an interface already built to do such shenanigans prepackaged for control chart work; is obvious use in real world.
1 Comment
dpb
on 1 Oct 2017
Edited: dpb
on 1 Oct 2017
Oh, and I didn't update the violation markers, either...for it one has two choices
- update the existing logical array to include all data, or
- keep a new array for the added data and second line in plot
The latter is probably better as it doesn't mix up the length of lines in the original plot but keeps the added data separate from the original only using the scale factor from original constant lines to adjust for increasing X
ADDENDUM
"The latter is probably better..."
Presuming it is desired to keep data after the control lines are established independent and distinguishable from the original, of course.
If that isn't important, then might as well just keep the one array of outliers and update it.
As per usual, the devil is in the details of what are specific intents/purposes as to what's the bestest solution.
Shirley Lowmaster
on 18 Feb 2021
How to input data rather than using 'load parts'?
1 Comment
dpb
on 18 Feb 2021
Use whatever is appropriate for the data file you have...I just copied one of the examples for the controlchart to have something to use as a starting point for the above; reading the data into MATLAB is really a totally separate issue from using a control chart.
See <Data-import-and-export> for overview of how to read data into MATLAB depending upon just what you have as starting point.
See Also
Categories
Find more on Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!