How can I place labels on the end of my line plots?

조회 수: 5(최근 30일)
Hunter
Hunter 2022년 11월 30일
댓글: Hunter 2022년 11월 30일
%%Question 1
clear clc
for r = 1:1:2
for a =[0.1 0.2 0.5 0.75 1.0]
if a==0
tend=0
else
tend=4/a
end
t=0:1:tend
c=r-r*exp((-a)*t)
hold on
title('First Order Response')
xlabel('time (s)')
ylabel ('c(t)')
plot(t,c)
end
hold off
end
& Output
% Below is the image I would like as the output but can not figure out how to aquire labels on the lines.
% Also wanting to have it not be a text box in the figure editor.

채택된 답변

DGM
DGM 2022년 11월 30일
편집: DGM 2022년 11월 30일
You can use text(). You might want to adjust things a bit to help with readability.
for r = 1:1:2
for a = [0.1 0.2 0.5 0.75 1.0]
if a==0
tend=0;
else
tend=4/a;
end
t=0:1:tend;
c=r-r*exp((-a)*t);
hold on
plot(t,c)
text(t(end),c(end),sprintf('%0.1f',a),'rotation',45)
end
hold off
end
ht = title('First Order Response');
ht.Position(2) = ht.Position(2)+0.05; % make a bit more room
xlabel('time (s)')
ylabel ('c(t)')

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by