Output missing when running Simulink model from script.

Hey everybody,
I am currently trying to run a automated simulation by running a simulink model from a matlab script. Everything works fine so far except of that the "to workspace" block doesn't return it's output to the matlab workspace when I run the simulink model with the command "sim(modelName, 'StopTime', '100');". When I click the play button of the Simulink model it does return the output to the matlab workspace.
Is there any possibility that I start the simulation from a matlab script and process the output vector right afterwards?
Thanks in advance!
Regards,
Lennart

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 8 月 26 日

0 投票

When you use sim(), the To Workspace block writes the data into the workspace of the function that called the sim() command. That function can act on the variables such as by using assignin('base').
When you start a model from a graphics menu, the To Workspace block writes the data into the base workspace.

6 件のコメント

Lennart
Lennart 2015 年 8 月 26 日
Hi there,
I am not sure what the assigning('base') would help here right now, since the function (I use a script! Not a function) does not have any access to the variable that is supposed to be generated by the "to workspace" block...
Just to make it clear again: I am using a script that runs the simulink model via sim(...) but as soon as it tries to access simout (the variable generated by the to Workspace-Block) it returns the error "Undefined function or variable 'simout'.
Walter Roberson
Walter Roberson 2015 年 8 月 26 日
For the purpose of debugging, put
whos
before and after the sim() call, to see whether any variables are being created.
Lennart
Lennart 2015 年 8 月 26 日
Noap doesn't show any differences. The list before the sim() command is the same as the one afterwards :/ Any suggestions???
B.ray
B.ray 2021 年 4 月 5 日
I have the same issue
Walter Roberson
Walter Roberson 2021 年 4 月 5 日
To Workspace can be configured to either write in the workspace of the calling function (or script) or else into the base workspace. If the expected output does not show up in the workspace of the calling function (or script) then try
evalin('base', 'whos')
to see if it showed up there.
swadexi dx
swadexi dx 2023 年 2 月 28 日
I have the same issue, the sim() function takes the output of simulink only from the integrator.

サインインしてコメントする。

カテゴリ

質問済み:

2015 年 8 月 26 日

コメント済み:

2023 年 2 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by