필터 지우기
필터 지우기

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
  댓글 수: 2
Kevin Holly
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
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
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