Extract information while drawing using polyline
37 views (last 30 days)
Show older comments
Hello,
I want to draw a polyline in a figure, while drawing the polyline i want to extract the the previous position and the current position but while drawing not when the draw is finished, i tried to use event listener as shown in the code bellow
figure;
ax = axes;
% Draw a polyline interactively
roi = drawpolyline(ax);
addlistener(roi,'MovingROI',@allevents);
addlistener(roi,'ROIMoved',@allevents);
function allevents(~,evt)
evname = evt.EventName;
disp(selectionType)
switch(evname)
case{'MovingROI'}
disp(['ROI moving previous position: ' mat2str(evt.PreviousPosition)]);
disp(['ROI moving current position: ' mat2str(evt.CurrentPosition)]);
case{'ROIMoved'}
disp(['ROI moved previous position: ' mat2str(evt.PreviousPosition)]);
disp(['ROI moved current position: ' mat2str(evt.CurrentPosition)]);
end
end
This code works only after the polyline is finished drawing, I want to be while drawing,
Could you please resolve my Isuue ?
Answers (1)
Shubham
on 6 Aug 2024 at 8:43
Hi El,
As per my understanding, you want to know the current and previous position of the points while you are using the "drawpolyline" function.
As @dpb mentioned, the "Polyline" ROI object only triggers the event listeners and their callbacks once the drawing is finished. This means there is no way to use "Polyline" ROI event listeners to capture the points' positions before you complete the "Polyline" ROI drawing.
However, you can set the "WindowButtonDownFcn" callback on the parent figure and define your custom logic to extract the coordinates of the points wherever the user clicks. This approach allows you to capture the points' positions in real-time as the user clicks to add points to the "Polyline" ROI.
For more information about "drawpolyline", refer to the documentation link:
Hope it helps!
Regards,
Shubham
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!