How do i set up a legend for a graph with variable parameters?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Davide Masiello
am 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 Kommentar
Davide Masiello
am 3 Nov. 2022
Bearbeitet: Davide Masiello
am 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");
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!