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.
Best Answer