I want to simulate a dynamics system 'mdl' using sim('mdl',parameters), and I want to get the simulation output at some specific time points, instead of time points determined by the ode solver. Is there any way that I can specify the time step of the simulink ode solver?
Like when using ode45, I can use ode45(odefun,tspan,y0) with tspan=0:0.1:1, can I still get simulation output at time points 0:0.1:1 with simulink?

 採用された回答

Kaustubha Govind
Kaustubha Govind 2011 年 7 月 11 日
編集済み: John Kelly 2014 年 5 月 27 日

3 投票

For variable-step solvers, you can do this by setting the Output options parameter on the Import/Export Pane of the Configuration Parameters window to either 'Produce additional output' or 'Produce specified output only' and entering the time array in Output times.

3 件のコメント

Hongkai Dai
Hongkai Dai 2011 年 7 月 11 日
It can be done with fixed-step solvers. I set the ode to ode4 by using setSimulinkParam('Solver','ode4'), and specify the options.FixedStep=dt, then sim('mdl',options) will give me the output at the equally dt spaced time points with 4th order Runge-Kutta. I will try the output options for the varaible-step solvers, thanks a lot!
Hongkai Dai
Hongkai Dai 2011 年 7 月 11 日
Thanks for your help! Do you know how to set the output options to "Produce specified output only" through command line?
Hongkai Dai
Hongkai Dai 2011 年 7 月 11 日
Thanks, I have found out, I can specify option.OutputOption, and then pass sim('mdl',option)

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

その他の回答 (2 件)

Fangjun Jiang
Fangjun Jiang 2011 年 7 月 11 日

2 投票

Yes, certainly you can! Why don't you try it and see the results.
Use the MATLAB supplied "f14" model as an example, you can specify a time vector with variable time step and then run simulation. open the model and make it to output the simulation time "tout" and "yout" at Simulation>Configuration Parameters...>Data Import/Export
t=[0:0.01:5,5.1:0.1:10]';
sim('f14',t);
all(t==tout)
ans =
1
>> size(tout)
ans =
551 1
>> size(yout)
ans =
551 2

3 件のコメント

Hongkai Dai
Hongkai Dai 2011 年 7 月 11 日
Thanks, I can set the FixedStep option to some number dt, then I have an equally spaced time points. But what if the time sequence is not equally spaced? Is there an option to be set?
Kaustubha Govind
Kaustubha Govind 2011 年 7 月 11 日
I don't think that is possible with fixed-step solvers. However, if what you want is to only get output signal values at specified time-steps, you can choose the least common divisor of your desired steps as the solver fixed-step and then extract the desired points from the logged outputs.
Fangjun Jiang
Fangjun Jiang 2011 年 7 月 11 日
See my edited answer above. I added an example with time vector with variable time step.

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

Fangjun Jiang
Fangjun Jiang 2011 年 7 月 11 日

0 投票

I guess a short answer to your question is YES. Since you already know how to use ode45(odefun,tspan,y0) with tspan=0:0.1:1, you can do the same with sim, sim('YouModelName',tspan) with tspan=0:0.1:1.

1 件のコメント

Hongkai Dai
Hongkai Dai 2011 年 7 月 11 日
Thanks a lot for your kind help! But Mathworks says such syntax are obsolete: http://www.mathworks.com/help/toolbox/simulink/ug/f11-61836.html#bsoh2ls. Anyway, your solution helps me a lot! Thanks!

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

カテゴリ

ヘルプ センター および File ExchangeProgrammatic Model Editing についてさらに検索

タグ

質問済み:

2011 年 7 月 11 日

編集済み:

2014 年 5 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by