Difference in behavior of Dashboard Push Button and App designer Button (matlab.ui​.control.B​utton) how to make it work?

24 visualizaciones (últimos 30 días)
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 ?

Respuesta aceptada

Gayathri
Gayathri el 21 de Nov. de 2024 a las 5:37
Hi @AK,
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.
  1 comentario
AK
AK el 21 de Nov. de 2024 a las 8:27
Thanks for clarification. This makes me clear about the difference of push button in app designer. Its also clear that it can not be used like other input items of app designer.
As using two bottons will overcowd my panel i will use state button instead.
Thanks

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Model, Block, and Port Callbacks en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by