How can i force simulink to use a set of data from another simulink model ?

1 view (last 30 days)
Hey,
I have a Simulink File, which generates some Data and exports it to my Workspace. My second Simulink file needs this data and therefore imports it. This also works wonderfully when I run each individual simulation myself. But now I want everything to run automatically with one click. So first simulation1 -> data is loaded -> simulation2 runs.
I have already tried it with the following code:
set_param('simulation1', SimulationCommand', 'start');
data_simulation2 = data_simulation1 + offset;
set_param('simulation2', SimulationCommand','start');
But the problem is that both simulations run, but the data is not transferred to the second simulation. Only after the second simulation is finished, the data is loaded.
LG
Lindrit

Accepted Answer

Paul
Paul on 17 Apr 2022
Try using the sim() command instead of set_param. I had trouble with the latter, but no problems with the former. This code worked fine for me, where y1 is a ToWorkspace output from sim1 and u2 is block paramter in sim2.
clear
out1 = sim('sim1');
u2 = out1.y1.Data;
out2 = sim('sim2');

More Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by