Multiple plots in a single graph

2 views (last 30 days)
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.

Accepted Answer

Star Strider
Star Strider on 11 Jun 2021
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.
.

More Answers (1)

Walter Roberson
Walter Roberson on 11 Jun 2021
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

Categories

Find more on 2-D and 3-D Plots 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!