Running two simulink model in close loop

5 次查看(过去 30 天)
I want to run two simulink models in loop. When the simulation starts, the first model should send states at time 't' to other simulink model. The other simulink model will take input at time 't' from first model and run its own calculation for time 't+20' seconds. That is it should be able to create a time trajectory (prediction) for the first model. The results of model two should be feedback to model one as input and the cycle should go on. I cannot find any direct command for this. Also, matlab function block inside simulink doesnt support sim command.
  1 个评论
Dr. JANAK TRIVEDI
One way to achieve this is to use a "for" loop in MATLAB and run the simulations for each time step, updating the inputs and outputs of each model for each iteration. After the first simulation is complete, you can store the results in a variable, and use it as the input for the next simulation.
Here is a general outline of the steps you can follow:
  1. Create two Simulink models and save them.
  2. In MATLAB, create a "for" loop with the desired number of iterations, where each iteration corresponds to one time step.
  3. Within the loop, set the inputs of the first model using the previous outputs of the second model or the initial conditions if it is the first iteration.
  4. Use the "sim" command to run the first model and store the outputs in a variable.
  5. Use the outputs of the first model as inputs to the second model, and run the simulation using the "sim" command.
  6. Store the outputs of the second model in a variable, which will be used as inputs for the next iteration.
  7. Repeat the process for the desired number of time steps.
You can also use Simulink Data Transfer blocks to pass data between the two models.

请先登录,再进行评论。

回答(1 个)

Aishwarya Shukla
Aishwarya Shukla 2023-3-3
I think your problem will get resolved by the solution given by @Dr. JANAK TRIVEDI in comments, still if you need further assistance you can ask!

类别

Help CenterFile Exchange 中查找有关 Modeling 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by