Using Structures and Vectors of Operating Point Values

This section continues the example from Example: Water-Tank System. At this stage in the example, linearization point objects and operating points have been created in the MATLAB® workspace. See Specifying Operating Points Using Functions for more information on creating operating point objects using functions.

Operating point objects store the operating point values. However, when you want to use an operating point's values to initialize the simulation of a model, it is useful to work with vectors of operating point values, or with Simulink® structures. Simulink structures have the benefits that you can use them to initialize models that reference other models using the Model block, and you do not need to worry about the ordering of states in the structure.

You can extract vectors and structures of operating point values from operating point objects using the functions getxu and getstatestruct. You can then use these vectors or structures to initialize a model for simulation. Models that reference other models using the Model block, must be initialized with a Simulink structure of values, such as those from simulation data, extracted with the getstatestruct function. See Importing and Exporting States in the Simulink documentation for details on initializing model reference models.

To extract a structure of operating point values from the operating point object, watertank_op, created in Extracting Values from Simulation, use the following command:

x=getstatestruct(watertank_op)

This extracts a structure of state values, x from the operating point object:

x = 
       time: 0
    signals: [1x2 struct]

To access the values within this structure, use the following syntax:

x.signals.values

which returns

ans =
    1.2469

ans =
    9.9927

Note that these values are in the same order as those used by Simulink.

To extract a vector of operating point values from the operating point object, watertank_op, use the following command.

[x,u]=getxu(watertank_op)

This extracts vectors of states, x, and inputs, u, as shown below.

x =
    9.9927
    1.2469

u =
     []

To create an operating point object from a vector, or structure, of values, such as those returned from a simulation, you can use the function setxu.To set operating point values in an operating point object using a vector or structure of known values, you can use the following command.

new_op=setxu(watertank_op2,x,u)

This command creates a new operating point, new_op, that is based on the operating point watertank_op2, but with the values from the vector or structure of state values, x, and the vector of input values, u.

The ordering of the states in x and the inputs in u must be the same as the ordering used by Simulink which is not necessarily the same as the order the states appear in the operating point object. When you extract values from simulation data they will already be in the correct order.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS