How can I use ginput through app designer in MATLAB R2021a?
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (1)
Bruce Rodenborn
am 19 Jan. 2024
0 Stimmen
The solution posted below, on the other hand, does work. The solution in this post states that the handlevisibility state should be "On", when it appears that it should be "CallBack". The correct solution can be found in this post: https://www.mathworks.com/matlabcentral/answers/392617-how-can-i-use-ginput-in-app-designer.
% Set up figure handle visibility, run ginput, and return state
fhv = app.UIFigure.HandleVisibility; % Current status
app.UIFigure.HandleVisibility = 'callback'; % Temp change (or, 'on')
set(0, 'CurrentFigure', app.UIFigure) % Make fig current
[x_r, y_r] = ginput(1);
plot(x_r,y_r,'wo','MarkerFaceColor','w', 'MarkerSize',16)
app.UIFigure.HandleVisibility = fhv; % return original state
Kategorien
Mehr zu Data Exploration finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
