Simulink Scope "Open at Simulation Start"
조회 수: 36 (최근 30일)
이전 댓글 표시
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
채택된 답변
Pratik
2023년 11월 30일
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
Fangjun Jiang
2023년 11월 30일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 View and Analyze Simulation Results에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!