Running two simulink model in close loop

5 ビュー (過去 30 日間)
Mukesh Pokaram Choudhary
Mukesh Pokaram Choudhary 2023 年 2 月 1 日
回答済み: Aishwarya Shukla 2023 年 3 月 3 日
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
Dr. JANAK TRIVEDI 2023 年 2 月 1 日
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 Center および File ExchangeModeling についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by