Main Content

Load State Information

Import Initial States

To initialize a simulation, you can use:

  • Final state information (with or without ModelOperatingPoint object) from a previous simulation

  • State information that you create in MATLAB®

Use Configuration Parameters > Data Import/Export parameters to import initial states.

  1. Enable the Initial state parameter.

  2. In the Initial state edit box, enter the name of the variable for the state information that you want to use for initialization.

The initial values that the variable specifies override the initial state values that the blocks in the model specify in initial condition parameters.

You can specify Dataset, structure, or structure with time data.

Initialize a State

You can initialize a specific state. This example creates an initial state structure for the x2 state of the vdp model. The x1 state is not initialized in the structure. Therefore, during simulation, Simulink® uses the value in the Integrator block associated with the x1 state.

  1. Open the model.

    open_system('vdp');
    
  2. Set the SaveFormat model argument to 'Structure'.

    set_param('vdp','SaveFormat','Structure');
  3. Obtain an initial state structure.

    states = Simulink.BlockDiagram.getInitialState('vdp');
  4. Set the initial value of the signals structure element associated with x2 to 2.

    states.signals(2).values = 2;
    
  5. Remove the signals structure element associated with x1.

    states.signals(1) = [];
  6. Use the states variable for the vdp model. Select the initial state configuration parameter.

    set_param('vdp','LoadInitialState','on','InitialState','states');
  7. Simulate the model and examine the initial values of x2 and x1.

    sim('vdp');
    states
    states = 
    
      struct with fields:
    
           time: 0
        signals: [1×1 struct]
    
    states.signals
    ans = 
    
      struct with fields:
    
                   values: 2
               dimensions: 1
                    label: 'CSTATE'
                blockName: 'vdp/x2'
                stateName: ''
        inReferencedModel: 0
               sampleTime: [0 0]
    

When you simulate the model, both states have the initial value of 2. The initial value of the x2 state is assigned in the states structure, while the initial value of the x1 state is assigned in its Integrator block.

Initialize States in Referenced Models

To initialize the states of a top model and the models that it references, use the structure or structure with time format or use operating point.

If the top model is in rapid accelerator mode, you cannot load discrete state data.

See Also

Model Settings

Objects

Related Topics