Difference in behavior of Dashboard Push Button and App designer Button (matlab.ui.control.Button) how to make it work?
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am using 2017b.
I created GUI panel in Simulink model using Dashboard blocks.
Push Button I used has behavior as : when I push it , its value is 1, after release its value is zero.
I upgraded my panel using App Designer.
In app designer I am using push button for same purpose.
When I tried to write code as below for push button callback
function ButtonPushed(app, event)
value = app.Button.Value;
if value==1
set_param('SampleModel/Constant','Value', num2str(value))
else
valuezero=0;
set_param('SampleModel/Constant','Value', num2str(valuezero))
end
end
I get error as :No appropriate method, property, or field 'Value' for class 'matlab.ui.control.Button'.
Yes there is State Button : But I am using it for different purpose i.e. press to keep value 1 , press again to make value 0.
I tried to set global variable on pushbutton call back. but i dont have option to clear it.
tried to check in existing topics regarding use of push button but its of no use.
Any suggessions ?
0 commentaires
Réponse acceptée
Gayathri
le 21 Nov 2024 à 5:37
The Button in App Designer will not work like a Push Button. Given your application, it would be more effective to add two separate buttons: one to set the constant block value to '1' and another to set it to '0'.
The callback function of a button will only be executed if the button is pressed and there is no value associated to the press of a button. Please find the code below which will set the value of contant block when the button is pressed.
function ButtonPushed(app, event)
app.a=1;
set_param('SampleModel/Constant','Value', num2str(app.a))
end
Similar code can be used to set a value of ‘0’ when the other button is pressed. Please make sure to define the variable “a” in the “properties” section.
For more information on “set_param” function, please use the following command to access the documentation page.
doc set_param
Hope you find this information helpful.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Model, Block, and Port Callbacks dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!