Passing information between level-2 matlab s-functions
조회 수: 9 (최근 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에서 Simulink Functions에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!