MATLAB Answers

Allow user to draw a line using mouse

43 ビュー (過去 30 日間)
John D
John D 2019 年 11 月 14 日
コメント済み: Adam Danz 2019 年 11 月 16 日
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 件のコメント

Ajay Kumar
Ajay Kumar 2019 年 11 月 14 日
Do you mean line on the axes in uifigure?
John D
John D 2019 年 11 月 14 日
Yes

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2019 年 11 月 14 日
編集済み: Adam Danz 2019 年 11 月 14 日
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 件のコメント

表示 13 件の古いコメント
Image Analyst
Image Analyst 2019 年 11 月 16 日
I think drawline() SHOULD work. If it doesn't do anything when the user clicks and drags out a line, then post your code.
And you might want to unaccept the answer until it's solved because many people won't even open your question if they see you've accepted an answer already.
John D
John D 2019 年 11 月 16 日
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 2019 年 11 月 16 日
Ok, good! If you start using a more recent release you could implement it in app designer, too (r2019b or later).

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2019a

Translated by