按钮按下状态属性GUI MATLAB
推送btn1时,是否有可能更改btn1值或其某种状态/属性 例如: 我的GUI中有两个按钮btn1和btn2。当我单击btn1时,其自身的值/标志/状态自动更改为另一个值(可能为true/1),因此我可以在代码中使用它来执行一些操作 有没有其他选择?除了全局值按钮按下状态属性GUI MATLAB,matlab,properties,uibutton,matlab-gui,Matlab,Properties,Uibutton,Matlab Gui,推送btn1时,是否有可能更改btn1值或其某种状态/属性 例如: 我的GUI中有两个按钮btn1和btn2。当我单击btn1时,其自身的值/标志/状态自动更改为另一个值(可能为true/1),因此我可以在代码中使用它来执行一些操作 有没有其他选择?除了全局值 我真的很想以编程的方式进行,如果可能的话,避免使用appdesigner。您有使用回调函数的经验吗 您可以尝试运行此程序并将其应用于您的问题 function buttonTest % create figure fig = figure
我真的很想以编程的方式进行,如果可能的话,避免使用appdesigner。您有使用回调函数的经验吗 您可以尝试运行此程序并将其应用于您的问题
function buttonTest
% create figure
fig = figure;
% create first push button
btn1 = uicontrol(...
'Parent',fig,...
'style','pushbutton',...
'units','normalized',...
'Position',[0.1 0.15 0.8 0.2],...
'String','BTN 1',...
'Callback',@myfunction);
% create second push button
btn2 = uicontrol(...
'Parent',fig,...
'style','pushbutton',...
'units','normalized',...
'Position',[0.1 0.65 0.8 0.2],...
'String','BTN 2',...
'Callback',@myfunction);
% Generate loop to automatically run function behind push buttons
for i = 1:5
myfunction(btn1)
pause(1)
myfunction(btn2)
pause(1)
end
%% Callback function
function myfunction(source,~)
% detect source from call and display it.
if strcmpi(source.String,'BTN 1')
disp('BTN 1 pushed')
elseif strcmpi(source.String,'BTN 2')
disp('BTN 2 pushed')
end
end
end
您当然应该运行自己的方案,而不是显示按下的按钮