I need help setting a pushbutton in a GUI
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have started creating a GUI and I have ploted a point in the GUI on a graph. I have a push button that I want to be able to use to randomize the point. I need to write a function for this but I'm unsure of how to do so.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1212488/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1212493/image.png)
0 Kommentare
Akzeptierte Antwort
Voss
am 29 Nov. 2022
Bearbeitet: Voss
am 29 Nov. 2022
% (you can specify all those properties at the same time as you create the
% uicontrol)
my_third_button = uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[0.65 0.05 0.3 0.15], ...
'String','Randomize', ...
'Callback',{@randomize,plot_point_handle}); % pass the line handle as an additional argument to the Callback function
% Define the Callback:
function randomize(~,~,h)
% h is the handle to the plotted line (a.k.a. "plot_point_handle" in the calling workspace)
new_point = randn(2,1);
set(h,'XData',new_point(1),'YData',new_point(2));
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!