MATLAB Answers

How draw lines between two coordinates saved with mouse's click in UIaxes (appdesigner)?

5 views (last 30 days)
Hello all,
Someone help me please. I want draw lines between two coordinates (with mouse's click) that are showed on a UIaxes with scatter. I worked this in Appdesigner. The
sequence that i have in mind is:
  1. Click in button to draw.
  2. Click first point showed with scatter command in UIaxe.
  3. Click second point showed with scatter command in the same UIaxe.
  4. Right click to finish draw.

  0 Comments

Sign in to comment.

Accepted Answer

Kiran Felix Robert
Kiran Felix Robert on 26 Aug 2020
Edited: Kiran Felix Robert on 26 Aug 2020
Hi Ivan,
The UIAxes of App Designer does not have a callback functionality but the WindowButtonDown Callback function can be used. To get the mouse coordinates with respect to the axes created, the get function can be used with the ‘CurrentPoint’ and referencing the Axes handle (Refer to this Answer).
The following functions shows an example implementation of the callbacks for your application. Here I have used a separate ‘Finish’ button to plot the line, you can also use the SelectionType, if required for a ‘’right-mouse-click” button functionality
% Window button down function: UIFigure
function UIFigureWindowButtonDown(app, event)
P = get(app.UIAxes,'CurrentPoint');
if(length(app.X)<2)
app.X =[app.X P(1,1)];
app.Y = [app.Y P(1,2)];
scatter(app.UIAxes,app.X,app.Y);
end
end
% Button pushed function: FinishButton
function FinishButtonPushed(app, event)
line(app.UIAxes,app.X,app.Y)
app.X = [];
app.Y = [];
end
Kiran Felix Robert

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!