- Create two Simulink models and save them.
- In MATLAB, create a "for" loop with the desired number of iterations, where each iteration corresponds to one time step.
- 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.
- Use the "sim" command to run the first model and store the outputs in a variable.
- Use the outputs of the first model as inputs to the second model, and run the simulation using the "sim" command.
- Store the outputs of the second model in a variable, which will be used as inputs for the next iteration.
- Repeat the process for the desired number of time steps.
Running two simulink model in close loop
6 views (last 30 days)
Show older comments
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 Comment
Dr. JANAK TRIVEDI
on 1 Feb 2023
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:
You can also use Simulink Data Transfer blocks to pass data between the two models.
Answers (1)
Aishwarya Shukla
on 3 Mar 2023
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!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!