Executing Simulink Code before the Simulation

8 vues (au cours des 30 derniers jours)
Lucas
Lucas le 19 Sep 2014
Réponse apportée : Lucas le 20 Sep 2014
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

Réponse acceptée

A Jenkins
A Jenkins le 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.

Plus de réponses (1)

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

Catégories

En savoir plus sur Programmatic Model Editing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by