Search code examples
matlabmatlab-app-designer

Extract drawline coordinates in App designer


How can I get extract the x1, y1, x2, y2 from the roi.Position to matching variables (x1, y1, x2, y2)?

function drawLineButtonPushed(app, event)
   roi = drawline(app.myAxes)
   disp(roi.Position);
end

Solution

  • drawline allows the user to a draw a line connecting two points A and B on the chosen axis. The XY positions of A ([Ax Ay]) and B ([Bx By]) are simply:

    roi = drawline(app.myAxes);
    Ax = roi.Position(1);
    Bx = roi.Position(2);
    Ay = roi.Position(3);
    By = roi.Position(4);