Multiple plots in a single graph
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
an Electrical Engineering Student
le 11 Juin 2021
Réponse apportée : Star Strider
le 11 Juin 2021
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.
0 commentaires
Réponse acceptée
Star Strider
le 11 Juin 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.
.
0 commentaires
Plus de réponses (1)
Walter Roberson
le 11 Juin 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
0 commentaires
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



