Simulink Scope "Open at Simulation Start"
36 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jeffrey Topp
am 30 Nov. 2023
Kommentiert: Jeffrey Topp
am 1 Dez. 2023
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?
0 Kommentare
Akzeptierte Antwort
Pratik
am 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.
4 Kommentare
Fangjun Jiang
am 30 Nov. 2023
Good to know! I thought I saw somewhere that 'on'/'off' can be replaced by 1/0.
But in R2022b, num2str() still can't be applied. That is my point.
>> set_param(gcb,'OpenAtSimulationStart','off')
>> set_param(gcb,'OpenAtSimulationStart','on')
>> set_param(gcb,'OpenAtSimulationStart',1)
>> set_param(gcb,'OpenAtSimulationStart',0)
>> set_param(gcb,'OpenAtSimulationStart',true)
Invalid setting in Scope block 'Scope6' for parameter 'OpenAtSimulationStart'
Caused by:
Option specified is not valid.
>> set_param(gcb,'OpenAtSimulationStart',false)
Invalid setting in Scope block 'Scope6' for parameter 'OpenAtSimulationStart'
Caused by:
Option specified is not valid.
>> set_param(gcb,'OpenAtSimulationStart',num2str(1))
Invalid setting in Scope block 'Scope6' for parameter 'OpenAtSimulationStart'
Caused by:
Option specified is not valid.
>> set_param(gcb,'OpenAtSimulationStart',num2str(0))
Invalid setting in Scope block 'Scope6' for parameter 'OpenAtSimulationStart'
Caused by:
Option specified is not valid.
>> set_param(gcb,'OpenAtSimulationStart',num2str(true))
Invalid setting in Scope block 'Scope6' for parameter 'OpenAtSimulationStart'
Caused by:
Option specified is not valid.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu View and Analyze Simulation Results finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!