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일
편집: 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일

0 개 추천

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

John D
John D 2019년 11월 14일
Thanks for the reply.
However, I get the following error:
Error using images.roi.internal.ROI/parseInputs
ROI parent must be a valid Axes object.
Error in images.roi.Line
Error in drawline (line 158)
h = images.roi.Line(varargin{:});
Adam Danz
Adam Danz 2019년 11월 14일
편집: Adam Danz 2019년 11월 14일
What handle are you providing to drawline()? As the error indicates, it must be a handles to an axis or UIAxis. What version of matlab are you using?
John D
John D 2019년 11월 14일
I'm using version 2019a
Adam Danz
Adam Danz 2019년 11월 14일
The first question was more important.
John D
John D 2019년 11월 15일
The handle I am providing is "app.UIAxes" which is the name of an axes control in my app.
I have tried this in MATLAB online and it seems to work, but offline, this error appears.
Adam Danz
Adam Danz 2019년 11월 15일
Maybe it's a version issue. I have r2019a available and can test this in a couple of hours and get back to you.
John D
John D 2019년 11월 15일
Thanks
Adam Danz
Adam Danz 2019년 11월 15일
편집: Adam Danz 2019년 11월 15일
John, I confirmed that drawline() was not supported for UIAxes in r2019a. It is supported in r2019b. Unfortunately imline() also isn't supported for uiaxes in r2019a (it uses a context menu which doesn't fly with UIAxes).
Option 1 is to use a newer release of Matlab (lots of changes were made to App Designer between 2019a and 2019b so you'd have multiple benefits.
Option 2 is to try to come up with an alternative solution. Could you describe what the purpose of the line will be? Should it always be horizontal or vertical?
John D
John D 2019년 11월 15일
Unfortunately, I'm limited to use R2019a.
However, I would like the user to click and drag on the axis to draw a line in a similar way. This would be a straight line drawn in any direction.
Could you suggest a workaround?
Thanks so far for your help.
Adam Danz
Adam Danz 2019년 11월 15일
편집: Adam Danz 2019년 11월 15일
Hi John, I just toyed around with it for a while. Interactivity with UIAxes in r2019a is really limited. In fact, UIAxes don't even support for callback functions in r2019a. When I tried to add a ButtonDownFcn, an error indicated a lack of support.
Much (if not all) of these features are supported in r2019b. There's probably a creative, albeit messy, solution out there but I've ran out of time for the day.
As a comparison, check out the list of interaction and callback methods available for UIAxes in r2019b
vs r2019a
John D
John D 2019년 11월 15일
Ok, thanks for your help.
Would this functionality be available in GUIDE, out of interest?
Adam Danz
Adam Danz 2019년 11월 16일
I'm not sure which function you're asking about. drawline() should work on regular axes used by guide GUIs.
John D
John D 2019년 11월 16일
I was asking would the user be able to draw a line with their mouse on an axes in GUIDE, but I've tested it with the same code and it doesn't seem to do anything.
Thank you for your help!
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일
편집: 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개)

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2019년 11월 14일

댓글:

2019년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by