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 約23時間 前
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 約20時間 前
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 Center および File ExchangeModel, 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