How to connect points in a plot with a line
34 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Edgar Dominguez Ugalde
el 15 de En. de 2018
Comentada: Edgar Dominguez Ugalde
el 15 de En. de 2018
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:

Respuesta aceptada
Image Analyst
el 15 de En. de 2018
Editada: Image Analyst
el 15 de En. de 2018
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 comentarios
Image Analyst
el 15 de En. de 2018
Editada: Image Analyst
el 15 de En. de 2018
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!