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

2 ビュー (過去 30 日間)
Alex Milns
Alex Milns 2023 年 11 月 19 日
回答済み: Voss 2023 年 11 月 19 日
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;

採用された回答

Voss
Voss 2023 年 11 月 19 日
%% 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');

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePolar Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by