Azzera filtri
Azzera filtri

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

36 visualizzazioni (ultimi 30 giorni)
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 Commenti
Kevin Holly
Kevin Holly il 9 Giu 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 il 9 Giu 2023
It is probably a good idea to have a sketch of your GUI (or a screenshot), along with what you have already tried.

Accedi per commentare.

Risposte (1)

Divyanshu
Divyanshu il 12 Giu 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:

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by