How to show selected points and connect first point to last point?
11 views (last 30 days)
I have the following code:
[x,y]=ginput(); % user can chose any number of coordinates by clicking on graph
Is there a way that when the user clicks in the graph, the selected points are marked (to show the selected points)?
Lastly, I want the first point to connect to the last point, but I am not sure how to do this.
I will appreaciate if someone can help me out with my two inquiries. Many thanks!
Daksh on 29 Sep 2022
It is my understanding that you wish to view marked points in real time as the user selects multiple points in a plot using "ginput" and you want all points connected, all the way from the first to the last in order through a line.
The following code illustatres how to achieve the same; I've assumed you know the number of points to be marked beforehand (I've taken 5 points in this case) and I've also put the number tag string on each marked point to depict the order of point marking:
%assuming you want to plot 5 points for example
%running a loop over all selected points
%allowing user to click a point to choose, x,y store the coordinates
[x,y] = ginput(1);
%text depiction for each point, with "i" as the point marker
h1 = text(x,y,int2str(i), ...
'Color', [1 0 0], ...
%plotting a line between all points
plot([a ; a(1)],[b ; b(1)], 'b-');
Hope it helps