Allow user to draw a line using mouse
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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 についてさらに検索
参考
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
