Passing information between level-2 matlab s-functions
7 次查看(过去 30 天)
显示 更早的评论
I am trying to model a two step chemical process using simulink and s function for each step. 5 outputs from step 1 are connected to the 5 inputs of step 2. I initialize the outputs of step 1 in its s function using read in parameters. When I initialize the state variables of step 2, which uses outputs from step 1, the values of the output the output variables of step 1 inside step 2 initialization are zero. What can I do to fix this?
Thanks. Girish
0 个评论
采纳的回答
Jarrod Rivituso
2011-4-12
Some background info that you may find useful...
- Simulink goes through an "initialization" phase prior to starting its simulation loop. Here it will call certain S-function methods for each block, such as the method that will initialize the state variables (for MATLAB S-functions, I believe this is the InitializeConditions block method).
- During the simulation loop, Simulink typically first computes all block outputs, then it will go back and compute updates to state values. This is the typical "Output" and "Update" functions.
One key thing to note is that the initialization part comes prior to any block outputs being produced. On that note, it sounds based on your description that you are trying to use a block input value during the initialization phase of the simulation. This is not going to work for you.
Each block must set its own initial state values based on initial conditions. You could use some MATLAB code outside of the S-functions to pass the correct initial values to each, if that is necessary.
1 个评论
Jarrod Rivituso
2011-4-12
Note that you can use the block sorted order to determine which block executes first. To do this, select Format -> Block Displays -> Sorted Order. The sorted order is determined automatically by Simulink based on which blocks rely upon which other blocks.
To be more clear, my suggestion is that you do the following
1. Write a MATLAB script that calculates the initial conditions for each block in the base workspace
2. Use the initial conditions calculated in the base workspace as parameter arguments to their appropriate S-functions.
3. In each S-function's "Initialize" method, set the initial values of the internal states to the parameter values of the S-function.
4. Use the state values in the "Outputs" method as you require.
Does that make sense?
更多回答(1 个)
Girish
2011-4-12
4 个评论
Jarrod Rivituso
2011-4-13
Generally, continuous state blocks will have the following kind of flow during the simulation loop:
Outputs – creates the block output using the current value of the continuous state
Derivatives – creates the derivative of the block using the current value of the input signal, and possibly other factors as well
另请参阅
类别
在 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!