File Exchange

image thumbnail

subroutines/PolyDra​w

version 2.0.0.0 by Brad
Draw polygons on a figure using a mouse and return the 2D coordinates

1 Download

Updated 04 Aug 2016

GitHub view license on GitHub

Draw polygons on a figure using the mouse.

Cite As

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

Comments and Ratings (3)

Brad

@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

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

Updates

2.0.0.0

Updated for back functionality to MATLAB versions prior to 2014b

1.2.0.0

word

1.1.0.0

Updated title

MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: draw