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

22 views (last 30 days)
%%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.

Accepted Answer

DGM
DGM on 30 Nov 2022
Edited: DGM on 30 Nov 2022
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)')

More Answers (0)

Community Treasure Hunt

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

Start Hunting!