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

13 次查看(过去 30 天)
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 ?

采纳的回答

Gayathri
Gayathri about 9 hours 前
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 个评论
AK
AK about 6 hours 前
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Model, Block, and Port Callbacks 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by