Need helps for data disappear after running "sim"

2 views (last 30 days)
Hello everyone, I am a simulink learner. I have one problem with date save related with "sim". Thank you for helping. Problem statement: When running the "sim('model')", the variables names of the simulink model can be seen in the matlab base Workspace. But when "sim" command is completed and continues to the following codes, all those mdl variables disappear from the workspace, even the "save to space" ports are set in simulink model. I do not how to solve this problem. Thanks for any suggestion and help!

Accepted Answer

Andreas Goser
Andreas Goser on 5 Aug 2011
Try this
[x,y]=sim('vdp');
Use the SIM command with return variables like described in the doc
  3 Comments
J T
J T on 5 Aug 2011
I think I should discribe the problem statement in this way: In my simulink model A, there are several masked subsytems (a,b,c.. ), in which the parameters are defined ({x1} for a; {x2} for b;...).
The output port "Out1" of model A denotes my object result, but it should be a iterative result.
I have to set a loop run for model A based on intial [{x1}, {x2}, {x3}... ]. The "Out1" should be returned to main arithmetical program, and the main program will assign updated {x1'} for masked system a; {x2'} for masked system b;...
I am using the "sim" in the circumstant, and met all these problems.
Thank you. I am not sure which commands are supposed to use. Or there is more suitable command? Thank you.
Andreas Goser
Andreas Goser on 5 Aug 2011
I am afraid your descriptions confuse me. The SIM command is used when you want to control simulations through MATLAB, e.g. for parameter studies. Your description is not clear to me, but it sounds like it is a valid reason to work with SIM.
Now to the masked subsystems. I do not see a reason why this matters.
About the returned data. When you use "To Workspace" blocks, the data will be in the base workspace. Maybe your MATLAB Code is a function and not a script and thus, the return data is in the function's workspace.

Sign in to comment.

More Answers (0)

Categories

Find more on Modeling in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!