I need help setting a pushbutton in a GUI

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.

 채택된 답변

Voss
Voss 2022년 11월 29일
편집: Voss 2022년 11월 29일

0 개 추천

% (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

댓글 수: 1

Amanda
Amanda 2022년 11월 29일
I also need to add a new point when you press the add point but that displays a different marker for each new point

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

질문:

2022년 11월 29일

댓글:

2022년 11월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by