Borrar filtros
Borrar filtros

Problems with sim command in Matlab 2020a

7 visualizaciones (últimos 30 días)
Buddy
Buddy el 12 de Oct. de 2020
Comentada: stozaki el 13 de Oct. de 2020
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 comentarios
Buddy
Buddy el 12 de Oct. de 2020
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 el 13 de Oct. de 2020
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

Iniciar sesión para comentar.

Respuestas (1)

stozaki
stozaki el 12 de Oct. de 2020
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 comentarios
Buddy
Buddy el 12 de Oct. de 2020
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 el 13 de Oct. de 2020
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

Iniciar sesión para comentar.

Categorías

Más información sobre Programmatic Model Editing en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by