MATLAB: Add circles to starting and ending point of a line

line covex circleMATLAB

Hi,
I am looking for a way to add a circle at both Ends of a line, as done manually in the Picture shown in the Appendix.
In Addition, I would also like to add such a circle in the middle of the line (at x=9) for both the cruve and the staigth line, in order to Show the convexity and therefore the value of the Point on the line being larger than the one on the curve

Best Answer

x = [1 17];
y= [19.99 18.57];
line(x,y,'Color','r','LineWidth',4)
radius = 1;
centerX = 1;
centerY = 19.99;
rectangle('Position',[centerX - radius, centerY - radius, radius*2, radius*2],...
'Curvature',[1,1],...
'FaceColor','r');
axis square;
centerX = (1+17)/2;
centerY = (19.9+18.57)/2;
rectangle('Position',[centerX - radius, centerY - radius, radius*2, radius*2],...
'Curvature',[1,1],...
'FaceColor','r');
axis square;
radius = 1;
centerX = 17;
centerY = 18.57;
rectangle('Position',[centerX - radius, centerY - radius, radius*2, radius*2],...
'Curvature',[1,1],...
'FaceColor','r');
axis square;