Executing Simulink Code before the Simulation
8 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
A Jenkins
2014-9-19
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.
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!