Allow user to draw a line using mouse

10 Ansichten (letzte 30 Tage)
John D
John D am 14 Nov. 2019
Kommentiert: Adam Danz am 16 Nov. 2019
How can I get a user to draw a line using their mouse in an App Designer app using R2019a?
Edit: If App Designer does not support it, will GUIDE?
Thanks in advance.
  2 Kommentare
Ajay Kumar
Ajay Kumar am 14 Nov. 2019
Bearbeitet: Ajay Kumar am 14 Nov. 2019
Do you mean line on the axes in uifigure?
John D
John D am 14 Nov. 2019
Yes

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Adam Danz
Adam Danz am 14 Nov. 2019
Bearbeitet: Adam Danz am 14 Nov. 2019
If you have the image processing toolbox, use drawline(). Something will have to trigger the function such as a button press or context menu selection. The example below responds to a button press which will then allow the user to click-and-drag a single line on an existing UIAxes.
function ButtonPushed(app, event)
hold(app.UIAxes, 'on')
drawline(app.UIAxes)
% ^^^^^^^^^^ your ui axis handle
end
  16 Kommentare
John D
John D am 16 Nov. 2019
Bearbeitet: John D am 16 Nov. 2019
I have tried it again in a new app, and have now got it to work in GUIDE.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
drawline(handles.axes1);
Adam Danz
Adam Danz am 16 Nov. 2019
Ok, good! If you start using a more recent release you could implement it in app designer, too (r2019b or later).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by