MATLAB Answers

How can I use ginput through app designer in MATLAB R2021a?

46 ビュー (過去 30 日間)
Mohammad Shahbazy
Mohammad Shahbazy 2021 年 4 月 22 日
コメント済み: Mohammad Shahbazy 2021 年 4 月 23 日
Hi all,
I am interested in writing a code for a push button in app designer to run ginput to select several points in the 2D data space. My code is here:
% Button pushed function: plot
function plotButtonPushed(app, event)
x = rand(10000,1);
y = rand(10000,1);
plot(app.UIAxes,x,y,'.');
set(app.UIFigure,'CurrentAxes',app.UIAxes);
[x1,y1] = ginput(7);
hold on;
[k1 v1] = convhull(x1,y1);
plot(x1(k1),y1(k1),'c-',x1,y1,'m*','Parent',app.UIAxes);
end
when I run this, it prompts another figure window. I need to run it in the app environment. Would you please correct my code?
Thank you so much in advance,
Moh

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 4 月 22 日
編集済み: Cris LaPierre 2021 年 4 月 22 日
The issue is that, by default, your app's uifigure handle visibility is set to off. Since ginput can't see a figure, it creates one.
In your component browser (right pane), select your main figure (app.UIFigure), then in the inspector, expand Parent/Child and change HandleVisibility to 'on'.
I made some slight changes to your code when testing as well.
% Button pushed function: Button
function ButtonPushed(app, event)
x = rand(10000,1);
y = rand(10000,1);
plot(app.UIAxes,x,y,'.');
[x1,y1] = ginput(7);
hold(app.UIAxes,'on');
[k1 v1] = convhull(x1,y1);
plot(app.UIAxes,x1(k1),y1(k1),'c-',x1,y1,'m*');
hold(app.UIAxes,'off');
end
  1 件のコメント
Mohammad Shahbazy
Mohammad Shahbazy 2021 年 4 月 23 日
Hi Cris,
Thanks a lot. It works properly.
Best

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

その他の回答 (0 件)

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by