How to number a plot legend for the number of values a user inputs
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to a legend that reads "G(s) #1" for the first plot, "G(s) #2" and so on for the number of values the user inputs into the system.
Appreciate the help.
clear
s = tf('s');
zeta = input('Enter damping ratio values in a 1D array: ');
omega = input('Enter natural frequency values in a 1D array: ');
stop = input('Enter stop time: ');
figure;
hold on;
for n = 1 : length(omega)
Gs = omega(n)^2 / ((s^2) + (2*zeta(n)*omega(n)*s) + omega(n)^2);
step(Gs, stop);
end
hold off;
title({['Unit Step Response of G(s) = \omega_{n}/(s^2 + 2\zeta\omega_{n}s + \omega_{n}^2)'], ...
['\zeta = ', num2str(zeta(n)), ' and \omega_n = ', num2str(omega(n))]});
ylabel('System Response');
legend ('G(s) #')
0 comentarios
Respuestas (1)
Dyuman Joshi
el 3 de Ag. de 2023
Use compose
%Random value for example
n = 5;
str = compose("G(s) #%d", 1:n)
%use the generated string as legend
legend(str)
1 comentario
Voss
el 3 de Ag. de 2023
Another option is to use string concatenation:
n = 5;
str = "G(s) #" + (1:n)
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!