Problems with sim command in Matlab 2020a

조회 수: 10 (최근 30일)
Buddy
Buddy 2020년 10월 12일
댓글: stozaki 2020년 10월 13일
I am using a simulation model whcih has a To Workspace block named Results. In the Configuration Parameters dialog, the option 'Single Simulation Output' is not checked.
The thing is that when I click the Run button, I see that the Results variable is correctly generated in the workspace of Matlab. However, when I run the same simulation using the sim command from Matlab, the variable Resutls is not created but an object variable of type SimulationOutput named 'ans'.
May anyone help me with this. Thanks in advance.
  댓글 수: 2
Buddy
Buddy 2020년 10월 12일
Just one comment.
I just realized that when using the following command:
sim (mdl_name); (mdl_name is a variable with the name of the simulink model)
The Results variable is created.
However, with the following command: sim (mdl_name, 'StopTime', '5');
The Results variable is not created but the 'ans' object I mentioned before
stozaki
stozaki 2020년 10월 13일
Hi,
Do you set the return value of sim (mdl_name,'StopTime', '5') ;?
results = sim (mdl_name,'StopTime', '5') ;.
"ans" is the default return value if you have not set a return value.
stozaki

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

답변 (1개)

stozaki
stozaki 2020년 10월 12일
Hello
Is the result of the following command ”ans” ?
get_param (bdroot (gcs),'ReturnWorkspaceOutputsName')
If you turn on the value of the "Single simulation output" property, you will get the signals, states, outputs, etc. all in one output object. If you turn off the value of the "Single simulation output" property, you will get each output individually.
Since you are using the To Workspace block, you can get the value of Workspace by accessing the Data property from the ans object.
result = ans.simout.Data
You can also get the time data from the ans.tout property.
times = ans.simout.Time
Please also refer to what I have answered in the past.
stozaki
  댓글 수: 2
Buddy
Buddy 2020년 10월 12일
Thanks for your answer.
The point is that in my model the "Single simulation output" text box (either checked or not) has the value "out" not "ans". The "ans" object that is generated by Simulink in Matlab does contain the variable "Results" but I do not know why this object is named "ans".
stozaki
stozaki 2020년 10월 13일
Hi,
Do you set the return value of sim (mdl_name,'StopTime', '5') ;?
results = sim (mdl_name,'StopTime', '5') ;.
"ans" is the default return value if you have not set a return value.
stozaki

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

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by