Multiple plots in a single graph

조회 수: 17 (최근 30일)
an Electrical Engineering Student
답변: Star Strider 2021년 6월 11일
I have the following code for a ball & beam system:
m = 0.111;
R = 0.015;
g = -9.8;
L = 1.0;
d = 0.03;
J = 9.99e-6;
s = tf('s');
P_ball = -m*g*d/L/(J/R^2+m)/s^2
figure(1)
pzmap(P_ball)
grid
figure(2)
step(P_ball)
grid
How can I plot multiple curves of the step response of the system for different values of m, all in the same graph? I don't mean to separate them into different subplots within the same figure; instead, I need them all to share the same axes for ease of comparison.

채택된 답변

Star Strider
Star Strider 2021년 6월 11일
It is necessary to create them in a loop, storing them in a cell array. After that, a single call to the functions works —
m = 0.111*(1:5);
R = 0.015;
g = -9.8;
L = 1.0;
d = 0.03;
J = 9.99e-6;
s = tf('s');
for k = 1:numel(m)
P_ball{k} = -m(k)*g*d/L/(J/R^2+m(k))/s^2;
end
figure(1)
pzmap(P_ball{:})
grid
axis([-1 1 -1 1]*1E-3)
figure(2)
step(P_ball{:})
grid
legend(compose('m = %.3f',m), 'Location','best')
This works correctly in R2021a.
.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2021년 6월 11일
R = 0.015;
g = -9.8;
L = 1.0;
d = 0.03;
J = 9.99e-6;
s = tf('s');
for m = 0.09:.01:0.13
P_ball = -m*g*d/L/(J/R^2+m)/s^2;
figure(1)
pzmap(P_ball)
grid
hold on
figure(2)
step(P_ball)
grid
hold on
end

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by