Effacer les filtres
Effacer les filtres

Plot control at one figure and two subplots using built-in matlab functions

3 vues (au cours des 30 derniers jours)
I try to plot control chart plot, and add to grid to every plot. But if I try to plot charts: for examples xbar and r charts, using controlchart() I get only last second plot (r chart), with grid.
My trouble: how to plot two plots and one figure non separatly, for example, two subplots?
My code for plotting control charts:
Example Data: (for every rows calculate mean and r data for CCharts plot)
102.8339 99.8529 101.0326 101.1049 101.8252 ;
98.7412 99.9311 101.5525 101.7223 102.3790;
101.8622 100.1905 102.1006 103.5855 99.9418;
101.3188 98.0557 102.5442 100.3331 100.5314;
99.6923 102.4384 101.0859 101.1873 100.7275;
...
Code:
%% Parameters for the initial normal distribution
mu = 101;
sigma = 1;
%% Number of data points
n = 100; % Total number of data points
%% Sample size for each point on the control chart
sample_size = 5;
%% Generate the first 25-30 points with a normal distribution
initial_points = randn(25 + randi(6, 1), sample_size) * sigma + mu;
%% Generate the control chart data
flag = randi(3, 1);
if flag == 1
mu_new = mu + randi([-1, 1]) * randi([1, 2]) * 0.15; % Randomly update mu
after_points = randn(74 + randi(6, 1), sample_size) * sigma + mu_new;
elseif flag == 2
sigma_new = sigma + randi([2, 3]) * 0.05; % Randomly update sigma
after_points = randn(74 + randi(6, 1), sample_size) * sigma_new + mu;
else
after_points = randn(74 + randi(6, 1), sample_size) * sigma + mu;
end
data = [initial_points; after_points];
%% Create figure and plot
figure(1)
% Subplot 1 for the first control chart ('u' chart)
st1 = controlchart(data, 'charttype', 'xbar');
grid on;
grid minor;
title('Control Chart - Type xbar');
figure(2)
% Subplot 2 for the second control chart ('p' chart)
st2 = controlchart(data, 'charttype', {'r'});
grid on;
grid minor;
title('Control Chart - Type r');
And I want to plot two CCharts with grids, and code not work:
% Create figure
figure;
% Subplot 1 for the first control chart ('xbar' chart)
subplot(2, 1, 1);
st1 = controlchart(data, 'charttype', {'xbar'});
grid on;
grid minor;
% Subplot 2 for the second control chart ('r' chart)
subplot(2, 1, 2);
st2 = controlchart(data, 'charttype', {'r'});
grid on;
grid minor;
This code also not work:
st1 = controlchart(data, 'charttype', {'xbar','r'});
grid on;
grid minor;

Réponse acceptée

Voss
Voss le 19 Nov 2023
%% Parameters for the initial normal distribution
mu = 101;
sigma = 1;
%% Number of data points
n = 100; % Total number of data points
%% Sample size for each point on the control chart
sample_size = 5;
%% Generate the first 25-30 points with a normal distribution
initial_points = randn(25 + randi(6, 1), sample_size) * sigma + mu;
%% Generate the control chart data
flag = randi(3, 1);
if flag == 1
mu_new = mu + randi([-1, 1]) * randi([1, 2]) * 0.15; % Randomly update mu
after_points = randn(74 + randi(6, 1), sample_size) * sigma + mu_new;
elseif flag == 2
sigma_new = sigma + randi([2, 3]) * 0.05; % Randomly update sigma
after_points = randn(74 + randi(6, 1), sample_size) * sigma_new + mu;
else
after_points = randn(74 + randi(6, 1), sample_size) * sigma + mu;
end
data = [initial_points; after_points];
%% Create figure and plot
fig = figure();
st1 = controlchart(data, 'charttype', {'xbar','r'});
ax = findobj(fig,'Type','axes');
grid(ax,'on');
grid(ax,'minor');

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by