how do the Simulink examples open close scopes using a button

3 次查看(过去 30 天)
ok lots of Simulink examples have buttons to open or close a scope so you only have the screan you are intersted in up... how do i recreate the effect, i tried to copy one set of scopes and use differnt sorces but the copied buttons are connected to the original scop :(

回答(1 个)

Arun
Arun 2023-12-29
Hey Alden,
I understand that you want to use button to toggle the visibility (open or close) of scope in a Simulink model.
You can use a button to open or close the scope window by following the below steps:
  1. Add a ‘Push Button’ block from the Simulink Library Browser (Simulink/Dashboard).
  2. Right click the “Push Button” block and click properties.
  3. In the Porperties console, click on the callback tab.
  4. Configure a callback for the Button Block under OpneFcn Callback using the following code snippet:
%Callback for Button
if strcmp(get_param(uModel_name/Scopet, tOpeno), noni) %check if the button is on
set_param(Model_name/Scope, Open, off);
else
set_param(Model_name/Scope, Open, on);
end
Using this you can achieve the desired functionality. Enclosed is a screenshot of the attached model, which you can use for your reference:
For additional information regarding push button, please refer to the following MATLAB documentation : https://www.mathworks.com/help/simulink/slref/pushbutton.html
Hope this helps.

类别

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

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by