How to implement press and hold button for app designer?
27 ビュー (過去 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 で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!