필터 지우기
필터 지우기

Export data from simulink to workspace when using sim command

조회 수: 4 (최근 30일)
Hello,
I want to run automatically several SIMULINK simulations with different input variables values. I have created a .m for this purpose to read the values for each simulation, run the simulation and extract the output needed.
My problem is the following: If I run the simulink model directly (no using any .m nor any command line) the two blocks 'To Workspace' creates the proper variables in the simulink workspace. On the other hand, when I run the simulation calling them from the .m file, the variables from these two blocks do not appear and I cannot extract the info I need. What I have now is: sim('model',[0,0.1],simset('DstWorkspace','base')); but it does not work either. Maybe is only to rewirte the sim command, but if I write [t,x,y]=sim... I am not sure if the two variables that I need are inside y.
Thank you in advance

채택된 답변

Paulo Silva
Paulo Silva 2011년 6월 21일
[t,x,y]=sim(...
Returns the simulation's output matrix. Each column contains the output of a root-level Outport block, in port number order. If any Outport block has a vector input, its output takes the appropriate number of columns.
[t,x,y1,...,yn]=sim(...
Each yi returns the output of the corresponding root-level Outport block for a model that has n such blocks.
  댓글 수: 3
Titus Edelhofer
Titus Edelhofer 2011년 6월 22일
Hi Javier,
take a look at the simulation parameters (menu configuration). There you specify if the model should output or not ...?
Titus
Javier Guiterrez
Javier Guiterrez 2011년 6월 23일
Finally it has worked in the ususal way but I still do not know why.
t,x,y1,...,yn]=sim(... was the first thing I probed but after some problems it is working. Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Titus Edelhofer
Titus Edelhofer 2011년 6월 21일
Hi Javier,
usually I would prefer
[t,x,y] = sim('model', [0 0.1], simset('DstWorkspace', 'current'));
because when you put this into a function, you ToWorkspace blocks will save the output in the current workspace, i.e., where you call sim. Note, the call to sim (output variables) depends on the version of MATLAB you are using. I think that calling sim without output arguments makes a difference to calling with output, so you should use the call above even if you don't care about t, x and y.
Titus

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by