Problems with sim command in Matlab 2020a

9 visualizzazioni (ultimi 30 giorni)
Buddy
Buddy il 12 Ott 2020
Commentato: stozaki il 13 Ott 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 Commenti
Buddy
Buddy il 12 Ott 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 il 13 Ott 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

Accedi per commentare.

Risposte (1)

stozaki
stozaki il 12 Ott 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 Commenti
Buddy
Buddy il 12 Ott 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 il 13 Ott 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

Accedi per commentare.

Categorie

Scopri di più su Programmatic Model Editing in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by