Hi, I'm trying to join some points with a line in a point plot I have created in order to draw the figure shown (ignore the dimensions).
Here's my code so far:
%Data
thta = 60;
L1 = 600;
%Coordinates 1
P1 = [700;-50;0];
P2 = [600;-50;0];
P3 = [600;0;0];
P4 = [600;50;0];
P5 = [700;50;0];
%Coordinates 2
P6 = [500;-70;0];
P7 = [500;0;0];
P8 = [500;70;0];
P9 = [0;-70;0];
P10 = [0;70;0];
%Equation
rotz = [cosd(thta) -sind(thta) 0;sind(thta) cosd(60) 0;0 0 1];
%Final positions 1
pf1 = rotz*P1;
pf2 = rotz*P2;
pf3 = rotz*P3;
pf4 = rotz*P4;
pf5 = rotz*P5;
%Final positions 2
pf6 = rotz*P6;
pf7 = rotz*P7;
pf8 = rotz*P8;
pf9 = rotz*P9;
pf10 = rotz*P10;
% Point Plot
x1 = pf1(1,1);
y1 = pf1(2,1);
x2 = pf2(1,1);
y2 = pf2(2,1);
x3 = pf3(1,1);
y3 = pf3(2,1);
x4 = pf4(1,1);
y4 = pf4(2,1);
x5 = pf5(1,1);
y5 = pf5(2,1);
x6 = pf6(1,1);
y6 = pf6(2,1);
x7 = pf7(1,1);
y7 = pf7(2,1);
x8 = pf8(1,1);
y8 = pf8(2,1);
x9 = pf9(1,1);
y9 = pf9(2,1);
x10 = pf10(1,1);
y10 = pf10(2,1);
figure
g1 = plot(x1,y1,'s')
xlim([-100 800])
ylim([-100 800])
title('Posiciones finales')
hold on
g2 = plot(x2,y2,'s')
plot(x3,y3,'s')
plot(x4,y4,'s')
plot(x5,y5,'s')
plot(x6,y6,'s')
plot(x7,y7,'s')
plot(x8,y8,'s')
plot(x9,y9,'s')
plot(x10,y10,'s')
hold off
Any ideas?
The figure obtained in Matlab is the following:

댓글 수: 2

John BG
John BG 2018년 1월 15일
the points alone are not enough, you have to tell what connected to what points.
John BG
John BG 2018년 1월 15일
also, do you intend to be able to edit thickness, colour and style like in autocad?

댓글을 달려면 로그인하십시오.

 채택된 답변

Image Analyst
Image Analyst 2018년 1월 15일
편집: Image Analyst 2018년 1월 15일

2 개 추천

Use the line() or plot() function
line([x1, x2], [y1, y2], 'Color', 'w');
plot([x1,x2], [y1,y2], 'w-', 'LineWidth', 2);
Or use the annotation() function to draw arrows.

댓글 수: 4

I rewrote the code and have solved the problem, but thanks for your time
And I tried with your method but seems not to work
Image Analyst
Image Analyst 2018년 1월 15일
편집: Image Analyst 2018년 1월 15일
Well of course it works. I wrote the code for the purple image you showed so I made the lines white. If you plot individual points on a white background, like the code below your sample image, you'll have to make the lines some color other than white, for example red. This works:
line([x3, x4], [y3, y4], 'Color', 'r'); % Line between point 4 and point 5.
plot([x5,x6], [y5,y6], 'r-', 'LineWidth', 2); % Line between point 5 and point 6.
Yeah, it works. I wasn't seeing the lines because of the color. Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by