Simulink Scope "Open at Simulation Start"
19 views (last 30 days)
I have several scopes in my simulink model that I run from a GUI. I would like to provide users the option to open one or several of those scopes when the simulation runs. I know there's a checkbox on the scope menu for "Open at Simulation Start". Is there a way I can interact with that property from Matlab at the time I run the simulink model? I can create variables in the workspace based on the GUI checkbox status, but how can I feed that into the scope in the model?
Pratik on 30 Nov 2023
Yes, you can interact with the "Open at Simulation Start" property of a Scope block in Simulink using MATLAB. You can use the `set_param` function to modify the properties of the Scope block at the time you run the Simulink model.
Here's an example of how you can achieve this:
% Assuming you have a variable named 'openScope' in your workspace based on the GUI checkbox status
% 'openScope' should be a logical value indicating whether the scope should be opened at simulation start
% Set the name of the scope block in your Simulink model
scopeBlockName = 'YourScopeBlockName'; % Replace with the actual name of your scope block
% Set the 'Open at Simulation Start' property based on the 'openScope' variable
set_param([gcs '/' scopeBlockName], 'OpenAtSimulationStart', num2str(openScope));
Replace `'YourScopeBlockName'` with the actual name of your Scope block. This code will set the "Open at Simulation Start" property of the specified Scope block based on the value of the `openScope` variable in your MATLAB workspace.