Line inside a circle. Hold on not working
Show older comments
Hello, I am trying to plot an image of a circle, with 4 points and a line that goes through one of the points but the line is not showing up on the plot.
I am using hold on to have the scatter and the circle in the image but it won't show the line. Any ideas as to how to fix this? I have the equation of the line and I just need it to appear in the same plot as everything else. Is there an easier way? Thank you!

xlocs=[0 -67.4066 -67.5774 -0.1715]; %mm
ylocs=[0 -0.3384 67.0755 67.1668];
%Tilt Line Tline4=pt4+t*o
t= linspace(0,1,4);
r4x=-0.1715+ t*(-0.1021);
r4y=67.1668 +t*(1.0773);
hold on; grid on;axis square;
radius = 55; %Making the radius bigger to make it fit %circle/projectile face diameter 101.6mm=4in
centerX = -35;
centerY = 35;
plot(r4x,r4y);
hold on
rectangle('Position',[centerX - radius, centerY - radius, radius*2, radius*2],'Curvature',[1,1])
hold on
scatter(xlocs,ylocs,'filled','r')
text(xlocs,ylocs,labels,'VerticalAlignment','bottom','HorizontalAlignment','right')
xlabel('Position (mm)')
ylabel('Position (mm)')
xlim([-90 30])
ylim([-30 90])
labels = {'Pin 1','Pin 2','Pin 3','Pin4'};
hold off
Accepted Answer
More Answers (2)
The line is too short and you are not able to see it.
I make it to a blue dot with MarkerSize = 50,
xlocs=[0 -67.4066 -67.5774 -0.1715]; %mm
ylocs=[0 -0.3384 67.0755 67.1668];
%Tilt Line Tline4=pt4+t*o
t= linspace(0,1,4);
r4x=-0.1715+ t*(-0.1021);
r4y=67.1668 +t*(1.0773);
radius = 55; %Making the radius bigger to make it fit %circle/projectile face diameter 101.6mm=4in
centerX = -35;
centerY = 35;
plot(r4x,r4y,'b.','MarkerSize',50);
grid on;axis square;
hold on
rectangle('Position',[centerX - radius, centerY - radius, radius*2, radius*2],'Curvature',[1,1])
scatter(xlocs,ylocs,'filled','r')
labels = {'Pin 1','Pin 2','Pin 3','Pin4'};
text(xlocs,ylocs,labels,'VerticalAlignment','bottom','HorizontalAlignment','right')
xlabel('Position (mm)')
ylabel('Position (mm)')
xlim([-90 30])
ylim([-30 90])
hold off
1 Comment
Macarena Santillan
on 16 Feb 2022
Try this:
xlocs=[0 -67.4066 -67.5774 -0.1715]; %mm
ylocs=[0 -0.3384 67.0755 67.1668];
%Tilt Line Tline4=pt4+t*o
t= linspace(0,1,4);
r4x=-0.1715+ t*(-0.1021);
r4y=67.1668 +t*(1.0773);
hold on; grid on;axis square;
radius = 55; %Making the radius bigger to make it fit %circle/projectile face diameter 101.6mm=4in
centerX = -35;
centerY = 35;
plot(r4x,r4y);
hold on
rectangle('Position',[centerX - radius, centerY - radius, radius*2, radius*2],'Curvature',[1,1])
hold on
scatter(xlocs,ylocs,'filled','r')
labels = {'Pin 1','Pin 2','Pin 3','Pin4'};
text(xlocs,ylocs,labels,'VerticalAlignment','bottom','HorizontalAlignment','right')
xlabel('Position (mm)')
ylabel('Position (mm)')
xlim([-90 30])
ylim([-30 90])
labels = {'Pin 1','Pin 2','Pin 3','Pin4'};
hold off
% Draw lines between all points.
% Tack last point on
for k1 = 1 : length(xlocs)
for k2 = 1 : length(xlocs)
xl = [xlocs(k1), xlocs(k2)];
yl = [ylocs(k1), ylocs(k2)];
line(xl, yl, 'Color', 'm', 'LineWidth', 2);
end
end
2 Comments
Macarena Santillan
on 16 Feb 2022
Image Analyst
on 16 Feb 2022
Point 4? Do you mean Pin 4? OK, but what are the endpoints of the line? Is one endpoint Pin 4? What is the other endpoint? What color do you want the line?
Categories
Find more on Display Image in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


