Multiple plots in a single graph

13 visualizaciones (últimos 30 días)
an Electrical Engineering Student
an Electrical Engineering Student el 11 de Jun. de 2021
Respondida: Star Strider el 11 de Jun. de 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.

Respuesta aceptada

Star Strider
Star Strider el 11 de Jun. de 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.
.

Más respuestas (1)

Walter Roberson
Walter Roberson el 11 de Jun. de 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

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by