Matlab App Designer - Press one button, then wait for the user to press another button, and get the name of the button pressed.

36 次查看(过去 30 天)
I would like to have the user select a button, then select another button to "link" the two buttons together. To do this, my plan was: once the first button is pushed, blink a lamp showing the program is waiting for another input, and then read the name/identifier of the next button that the user clicks on. I am unsure on how to do this, any advice would be much appriciated. Thanks

回答(1 个)

Divyanshu
Divyanshu 2023-6-12
Hi Bertie,
Here are few assumptions based on the description provided:
  • Linking two buttons is not physically linking instead it is a series of events getting linked.
  • And the app should indicate to the user that the app is waiting for another button to be pushed, after the first one is clicked.
Based on these, here is a sample application:
methods (Access = private)
% Code that executes after component creation
function SettingUpFlag(app)
app.Btn1PushedFlag = 0;
end
% Button pushed function: Button1
function Btn1Pushed(app, event)
app.Btn1PushedFlag = 1;
app.MessageEditField.Value = "Waiting for other button to be pushed";
app.ButtonPressedEditField.Value = "";
end
% Button pushed function: Button2
function Btn2Pushed(app, event)
if app.Btn1PushedFlag == 1
app.ButtonPressedEditField.Value = "Button2 is pushed";
app.MessageEditField.Value = "";
app.Btn1PushedFlag = 0;
else
app.ButtonPressedEditField.Value = "";
end
end
% Button pushed function: Button3
function Btn3Pushed(app, event)
if app.Btn1PushedFlag == 1
app.ButtonPressedEditField.Value = "Button3 is pushed";
app.MessageEditField.Value = "";
app.Btn1PushedFlag = 0;
else
app.ButtonPressedEditField.Value = "";
end
end
end
Please refer the following documentation for better understanding about ‘startupFcn’ callback:

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by