draw line between points in the figure
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
sermet
el 29 de Abr. de 2014
Comentada: Image Analyst
el 29 de Abr. de 2014
points_id={'p1','p2','p3','p4'}
x=[100,120,130,140] %coordinates
y=[200,220,330,340] %coordinates
figure(1),scatter(x, y, 'b^');grid on;
text(x, y, points_id)
title('COORDINATE SYSTEM')
xlabel('Y')
ylabel('X')
% in this figure I wanna draw lines between points when user click on corresponding points.
Respuesta aceptada
Image Analyst
el 29 de Abr. de 2014
Get the points, for example by using ginput. Then find out which of the points is closest to the 2 points they clicked on. Then draw a line between them. Here's a demo:
clc;
clear all;
workspace
points_id={'p1','p2','p3','p4'}
x=[100,120,130,140] %coordinates
y=[200,220,330,340] %coordinates
figure(1),scatter(x, y, 'b^');
grid on;
text(x, y, points_id)
title('COORDINATE SYSTEM')
xlabel('Y')
ylabel('X')
uiwait(msgbox('Click on two points', 'modal'));
[xu, yu] = ginput(2);
% Find the closest point to the first point where they clicked.
distances1 = sqrt((x-xu(1)).^2 + (y - yu(1)).^2)
[~, index1] = min(distances1)
% Find the closest point to the second point where they clicked.
distances2 = sqrt((x-xu(2)).^2 + (y - yu(2)).^2)
[~, index2] = min(distances2)
line([x(index1), x(index2)], [y(index1), y(index2)])
6 comentarios
Image Analyst
el 29 de Abr. de 2014
I don't have any sample/demo code for that. Either you or I would have to write it. I vote for you.
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Exploration 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!