Running two simulink model in close loop

5 visualizaciones (últimos 30 días)
Mukesh Pokaram Choudhary
Mukesh Pokaram Choudhary el 1 de Feb. de 2023
Respondida: Aishwarya Shukla el 3 de Mzo. de 2023
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 comentario
Dr. JANAK TRIVEDI
Dr. JANAK TRIVEDI el 1 de Feb. de 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:
  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.

Iniciar sesión para comentar.

Respuestas (1)

Aishwarya Shukla
Aishwarya Shukla el 3 de Mzo. de 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!

Categorías

Más información sobre Modeling en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by