Effacer les filtres
Effacer les filtres

How do I show which variable is being plotted while using hold?

3 vues (au cours des 30 derniers jours)
Connie Dubh
Connie Dubh le 9 Mai 2020
Commenté : Connie Dubh le 9 Mai 2020
I've modeled a state space system and now want to plot how the state variables change in time.
This is how I've set it up:
hx = phi_t * B
hy = C * phi_t * B
hx1 = [];
hx2 = [];
hx3 = [];
hx4 = [];
hx5 = [];
for i = 0:0.05:10
hx1 = [hx1 subs(hx(1), t, i)];
hx2 = [hx2 subs(hx(2), t, i)];
hx3 = [hx3 subs(hx(3), t, i)];
hx4 = [hx4 subs(hx(4), t, i)];
hx5 = [hx5 subs(hx(5), t, i)];
end
hold on
title('Impulse Response: State Vectors')
plot(hx1)
plot(hx2)
plot(hx3)
plot(hx4)
plot(hx5)
hold off
I'd like to know how I can show the names of the variables in the figure this code gives out, so I can know which is which (x1,x2,x3,x4 and x5). How can I do that?

Réponse acceptée

Star Strider
Star Strider le 9 Mai 2020
Modifié(e) : Star Strider le 9 Mai 2020
The legend function is the most obvious way to designate them. The text function is also an option. It depends on the result you want.
Example —
legend('x1','x2','x3','x4','x5')
.
  2 commentaires
Connie Dubh
Connie Dubh le 9 Mai 2020
Thanks a lot!
Star Strider
Star Strider le 9 Mai 2020
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 9 Mai 2020
Here is one of the possible easy solutions:
hx = phi_t * B
hy = C * phi_t * B
hx1 = [];
hx2 = [];
hx3 = [];
hx4 = [];
hx5 = [];
for i = 0:0.05:10
hx1 = [hx1 subs(hx(1), t, i)];
hx2 = [hx2 subs(hx(2), t, i)];
hx3 = [hx3 subs(hx(3), t, i)];
hx4 = [hx4 subs(hx(4), t, i)];
hx5 = [hx5 subs(hx(5), t, i)];
end
title('Impulse Response: State Vectors')
plot(hx1, 'b'), hold on, plot(hx2, 'r'), plot(hx3, 'b'), plot(hx4, 'k'), plot(hx5, 'm')
legend('x1', 'x2', 'x3', 'x4', 'x5', 'location', 'best')
hold off

Catégories

En savoir plus sur 2-D and 3-D 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!

Translated by