Allow user to draw a line using mouse
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
2019년 11월 14일
편집: Ajay Kumar
2019년 11월 14일
Do you mean line on the axes in uifigure?
John D
2019년 11월 14일
Yes
채택된 답변
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
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{:});
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
2019년 11월 14일
I'm using version 2019a
Adam Danz
2019년 11월 14일
The first question was more important.
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
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
2019년 11월 15일
Thanks
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
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.
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
2019년 11월 15일
Ok, thanks for your help.
Would this functionality be available in GUIDE, out of interest?
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
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
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.
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
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에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
