How to implement press and hold button for app designer?
조회 수: 13 (최근 30일)
이전 댓글 표시
I'm trying to implement a button where the button toggles as long as I press and hold the button (and disengages when I let go). With older Matlab versions, you could use functions like 'ButtonDownFcn' and 'WindowButtonUpFcn' to achieve this, but I'm now having a hard time with Matlab 2020a.
댓글 수: 0
답변 (1개)
Bala Tripura Bodapati
2022년 2월 8일
Hi Joe Hidler,
It is my understanding that you are not able implement a press and hold button for app designer, which toggles as along as it is pressed and held and disengages when released.
Currently there isn't a Button to specifically press and hold in the app designer. This issue is known, and the concerned parties may be investigating further. There is a possible workaround that can perform the similar functionality you want.
You can find "State Button" in the Component Library of the app browser. Refer here for more information:
and:
Clicking the state button once will turn the button "ON" until you click it again. So instead of holding and releasing you are clicking it once to effectively hold and clicking it again to effectively release the button. You can access the state of this button (1 i.e. true or 0 i.e. false) in other callbacks and functions to modify their behavior. This can be accessed by:
>> app.Button.Value (will be 1 i.e. true or 0 i.e. false)
% Note ('Button' has to be replaced by what you name this state button)
If you want to repeatedly run some code until you deactivate this button you can do that in its callback function. In the Design View, right click on the button and hover on Callbacks. There will be an option of "Add ValueChangedFcn callback". In that you can wrap your code in a while loop like:
function ButtonValueChanged(app, event)
while app.Button.Value % Replace 'Button' with what you name it
% Insert the code you want to run while the button is ON
end
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!