필터 지우기
필터 지우기

Simulink build a loop and define intial conditions

조회 수: 2 (최근 30일)
katherine keogh
katherine keogh 2021년 11월 16일
댓글: Jon 2021년 11월 18일
I want to build a loop in simulink with some intital conditions, and then for the next time step use the outputs as the inputs. How do I do this?

답변 (1개)

Jon
Jon 2021년 11월 16일
편집: Jon 2021년 11월 16일
In general you should be able to run your simulation iteratively by starting the simulation programatically using the MATLAB sim function (if you're not already familiar with the sim function, type doc sim on your command line to read the documentation)
So you would make a loop, something like this
for k = 1:numIterations
simout = sim('myModel',...)
% now do something with the output variables ...
% for example assign base workspace variable that are used as inputs in
% next loop
a = simout....
b = simout. ...
end
You may want to look at the documentation for the fast restart option, to avoid compiling the Simulink model with each iteration https://www.mathworks.com/help/simulink/ug/fast-restart-workflow.html
Exactly how you assign the outputs to the inputs depends upon what kind of values you are changing. However if they are values of constant blocks or mask parameter values that are assigned to base workspace variables it is as simple as reassigning these base workspace values (as I indicated in the example above)
  댓글 수: 2
Jon
Jon 2021년 11월 16일
Another idea would be to just run one long simulation and periodically feedback the outputs to the inputs within the simulation itself. So to do this you could use, for example, a unit delay block (from the discrete blocks in the Simulink library browser) with a long sampling time. The output(s) of your model would connect to the input of the unit delay block(s). The output of the unit delay blocks would connect to the input of your model. You would set the initial condition for the unit delay to get things started.
Jon
Jon 2021년 11월 18일
Were you able to get this running?

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

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by