MATLAB: [Waterloo] Draggable Line

Image Processing Toolboximrectjavalinewaterloo

I'm finding the Waterloo package very useful to enhance Matlab plots. However, I'm still wrapping my head around how to work directly with some of the Java objects. (Clearly, I'm not a Java programmer!)
For example, I have a very simple GXGraph() plot:
% Generate some fake data
x = linspace(-10, 10, 100); % X Data
y = sin(x./10 .* 2 .* pi); % Y Data
% Plot the Data
gfig = GXFigure(); % Waterloo figure handle
gr1 = subplot(gfig, 1, 1, 1); % Create Graph 1 (gr1)
data1 = scatter(gr1, x, y); % Plot a scatter graph
(Of course, the above example only works after Waterloo has been added to MATLAB's path, and the initial 'waterloo.m' script has been run.)
Now, I'd like to add a line to my graph. I can do this:
% Add a line
annotation(gr1, 'line', [5, 5], [-1, 1]); % Add Line
gr1.getObject().repaint(); % Update Graph
…But I don't know how to:
(1) allow the user to move the line
(2) add a callback to notify me when the line is moving
Ultimately, I'm trying to get something much like Matlab's native imrect() function — I want to define a resizeable region on my GXGraph.
Any suggestions?

Best Answer

I don't think that will work. annotation works on the whole figure unfortunately, not on the units of the axes control itself like you'd want. There was a discussion of this within the past two weeks. You can create draggable lines with imdistline() or improfile(), both in the Image Processing Toolbox.