File Exchange

## subroutines/PolyDra​w

Draw polygons on a figure using a mouse and return the 2D coordinates

Updated 04 Aug 2016

Draw polygons on a figure using the mouse.

### Cite As

Brad (2020). subroutines/PolyDraw (https://www.github.com/subroutines/PolyDraw), GitHub. Retrieved .

@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!

Bin Huang

### Bin Huang (view profile)

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
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
% 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);

delete(ax1);
plot(xys(1,:),xys(2,:),'b-','Parent',ax2);
drawnow
% ax1.delete
% plot(xys(1,:),xys(2,:),'b-','Parent',ax2);
% drawnow
end

%% -- DELETE (OR NOT) THE DRAWN POLYGON
if v3 >= 0
pause(v3)
if v2 == 1
delete(ax1);
else
delete(ax2)
end
% ax1.delete
% ax2.delete
end