How do i set up a legend for a graph with variable parameters?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hey,
i want to automize this legend, i do not want to write every case for the parameters.
t = -2:0.1:4;
d = 1;
c = 1;
hold on ;
for A=1:0.2:2
y= A * (t - d).*(t-c) ;
plot (t,y) ;
end
xlim ([-2 4]);
ylim([-1 5]) ;
grid on ;
xlabel('x-Achse');
ylabel('y-Achse');
titletext = 'Funktion f(x) = $A*(x-x1)*(x-x2)$';
title(titletext,Interpreter="latex");
leg = legend('1,0','1,2','1,4','1,6','1,8','2,0', Location='best');
title(leg,'A=');
hold off ;
What ae your Ideas?
And thanks for the help.
0 commentaires
Réponses (1)
Davide Masiello
le 3 Nov 2022
t = -2:0.1:4;
d = 1;
c = 1;
A = 1:0.2:2;
figure
hold on
for i = 1:length(A)
y= A(i) * (t - d).*(t-c) ;
plot (t,y)
end
xlim ([-2 4]);
ylim([-1 5]) ;
grid on
xlabel('x-Achse')
ylabel('y-Achse')
titletext = 'Funktion f(x) = $A*(x-x1)*(x-x2)$';
title(titletext,Interpreter="latex")
legend([repmat('A = ',length(A),1),num2str(A')], Location='best');
hold off
1 commentaire
Davide Masiello
le 3 Nov 2022
Modifié(e) : Davide Masiello
le 3 Nov 2022
Also note this can be done without loop
% parameters
t = -2:0.1:4;
d = 1;
c = 1;
A = 1:0.2:2;
% function
y = A'.*(t - d).*(t-c) ;
% plot
plot (t,y)
xlim ([-2 4]);
ylim([-1 5]) ;
grid on
xlabel('x-Achse',Interpreter="latex")
ylabel('y-Achse',Interpreter="latex")
title('Funktion f(x) = $A*(x-x1)*(x-x2)$',Interpreter="latex")
legend([repmat('A = ',length(A),1),num2str(A')], Location='best',Interpreter="latex");
Voir également
Catégories
En savoir plus sur Legend 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!