Executing Simulink Code before the Simulation

9 views (last 30 days)
Im am working on a model, which dynamically creates a Route consisting of various parts, which are characterized by a starting point (xyz_start) and an end point (xyz_end). The Route can be created by assembling those parts. Since I want to provide this (static) Route information to other parts of my simulation, I want to calculate the Route information before the actual simulation and store it in a data store memory. The calculation of the Route should not be executed during the simulation. My idea was to make this possible by enabled subsystems and an init parameter, which is 1 while the initialization and 0 while the simulation.
I know I have to work with Callback Functions but how can I execute the Code before the Simulation (e.g. for a specific time period) and change the init parameter after that, so that the Route informations are calculated and stored in the data store memory?
The model is attached. Thanks a lot for your help!
Note to the Data Store Memory: The Size is calculated by the count of Blocks with the Tag 'Strecke'. Rows: Blocks columns: 1 - block (1 if it is already taken, 0 if not) 2 - x-start of block 3 - y-start of block

Accepted Answer

A Jenkins
A Jenkins on 19 Sep 2014
1) You can use a Clock block with a Compare to Constant block to control blocks to only execute during parts of the simulation.
2) Alternatively, you could separate your simulations, so that your Main Simulation calls your Initialization Simulation before it even begins. In your MainSimulation.mdl, go to File->Model Properties->Callbacks->InitFcn, and add
sim('CreateRouteBeforeExecution')
Then you proabably need to add ToWorkspace and FromWorkspace blocks to pass the data between the two simulations.

More Answers (1)

Lucas
Lucas on 20 Sep 2014
Okay thanks. I think I will try the first suggestion, since I want to keep everything in one simulation!

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!