필터 지우기
필터 지우기

Simulink Scope "Open at Simulation Start"

조회 수: 36 (최근 30일)
Jeffrey Topp
Jeffrey Topp 2023년 11월 30일
댓글: Jeffrey Topp 2023년 12월 1일
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
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
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.
Jeffrey Topp
Jeffrey Topp 2023년 12월 1일
So I am able to execute this from the command line, but this requires the Simulink simulation be open. When I'm running from my Gui I don't require that. It should open up the simulation and the appropriate scopes.
So I tried to create a function block inside the simulation to execute the set_param commands. Simulink is telling me this function is "not supported for code generation".

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile 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!

Translated by