Draw polygons on a figure using the mouse.
Brad (2021). subroutines/PolyDraw (https://github.com/bradmonk/PolyDraw), GitHub. Retrieved .
Inspired: draw
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
@Bin Huang
Thanks for your feedback Bin. This is a version issue (you must be using a version of MATLAB prior to 2014b). I've updated the code to work with older versions of MATLAB per your specs. Cheers!
Great work.
However, it didn't total working on mine.
I slightly modified a little bit and it works and following are the modification i have done.
%% -- CREATE SOME AXES TO DRAW ON
% Added by BH -------------------------------------------------------------
position = get(ax, 'Position');
xLim = get(ax, 'XLim');
yLim = get(ax, 'YLim');
ax1 = axes('Position',position,'Color','none',...
'XLim',xLim,'YLim',yLim);
hold on
position = get(ax, 'Position');
xLim = get(ax, 'XLim');
yLim = get(ax, 'YLim');
ax2 = axes('Position',position,'Color','none',...
'XLim',xLim,'YLim',yLim);
hold on
% Added by BH -------------------------------------------------------------
% ax1 = axes('Position',ax.Position,'Color','none',...
% 'XLim',ax.XLim,'YLim',ax.YLim);
% hold on
% ax2 = axes('Position',ax.Position,'Color','none',...
% 'XLim',ax.XLim,'YLim',ax.YLim);
% hold on
%% -- INTERPOLATE (OR NOT) A SPLINE CURVE
if v2 == 2
t = 1:n;
ts = 1: 0.1: n;
xys = spline(t,xy,ts);
% Added by BH ---------------------------------------------------------
delete(ax1);
plot(xys(1,:),xys(2,:),'b-','Parent',ax2);
drawnow
% Added by BH ---------------------------------------------------------
% ax1.delete
% plot(xys(1,:),xys(2,:),'b-','Parent',ax2);
% drawnow
end
%% -- DELETE (OR NOT) THE DRAWN POLYGON
if v3 >= 0
pause(v3)
% Added by BH ---------------------------------------------------------
if v2 == 1
delete(ax1);
else
delete(ax2)
end
% Added by BH ---------------------------------------------------------
% ax1.delete
% ax2.delete
end