Multiple plots in a single graph

17 ビュー (過去 30 日間)
an Electrical Engineering Student
an Electrical Engineering Student 2021 年 6 月 11 日
回答済み: 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 Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by