Clear Filters
Clear Filters

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

36 views (last 30 days)
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
  2 Comments
Kevin Holly
Kevin Holly on 9 Jun 2023
How did you want to link the two buttons? Will they share the same callback function once linked? Will they visibly be linked?
Rik
Rik on 9 Jun 2023
It is probably a good idea to have a sketch of your GUI (or a screenshot), along with what you have already tried.

Sign in to comment.

Answers (1)

Divyanshu
Divyanshu on 12 Jun 2023
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:

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!