Matlab App Designer - Press one button, then wait for the user to press another button, and get the name of the button pressed.
20 次查看(过去 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
2 个评论
Kevin Holly
2023-6-9
How did you want to link the two buttons? Will they share the same callback function once linked? Will they visibly be linked?
Rik
2023-6-9
It is probably a good idea to have a sketch of your GUI (or a screenshot), along with what you have already tried.
回答(1 个)
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:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!