Create an internal loop in Simulink simulation

조회 수: 2 (최근 30일)
Benjamin
Benjamin 2013년 7월 6일
I am trying to create an internal loop (without using the if-loop blocks, because these seem to significantly slow down my model) to allow one part of my simulation to run for a specified number of times, and then output this so the rest of the simulation can continue. This would be the equivalent of a for loop inside a for loop, such as:
for(1:end of simulink simulation)
for(1:specified number of loops)
Run small part of simulation over and over
end
Run the rest of simulation
end
For a little context, this is for an iterative heat pump model, so that the heat pump portion can run several times to reduce error, and then the rest of the simulation can continue.
I was attempting to use a switch that is only thrown after a counter reaches a specified value, but I am unsure what to connect to the other side of the switch to prevent the rest of the simulation from continuing.

채택된 답변

Guru
Guru 2013년 7월 7일
The simplest way to implement this is to use Triggered or Function-call subsystems in Simulink driven by Stateflow (for the loop logic) or Embedded MATLAB Function block (at least that's what it used to be called when I used them in R2011b). After modeling this, you can either make sure your sorted order is appropriate for this operation, or simply use Stateflow to become your task scheduler so everything runs exactly how you want it to do.
HTH
  댓글 수: 1
Benjamin
Benjamin 2013년 7월 18일
Well, using Stateflow has helped me as a task manager, but I'm still unsure how to use it, or anything else, to create an internal loop. I need the loop to run while the rest of the simulation is effectively paused until it is done, and then continues with the output that the loop provided. (This loop is an algebraic loop that uses the previous timestep output for the current timestep output, which is why I need it to iterate a few times before proceeding - memory blocks and delays don't work in this scenario.)

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

추가 답변 (1개)

Guy Rouleau
Guy Rouleau 2013년 7월 18일
편집: Guy Rouleau 2013년 7월 18일
It looks like you need the While Iterator Subsystem:
  댓글 수: 1
Benjamin
Benjamin 2013년 7월 18일
Thanks Guy! I was hoping something exactly like that existed I just couldn't find it.

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

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by