Problems with sim command in Matlab 2020a

8 次查看(过去 30 天)
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 中查找有关 Sources 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by