Store and Retrieve Model Data

Model Properties

Model properties are the data fields that store all data about a dynamic system model. Data stored in model properties includes model dynamics, such as transfer-function coefficients, state-space matrices, and time delays. Model properties also let you specify other model attributes such as sample time, channel names, and state names.

For information about the properties associated with each model type, see the corresponding reference page, such as tf, pid, or ss.

Specify Model Properties at Model Creation

When you create a dynamic system model, the software sets all property values. Properties that contain model dynamics are automatically set with the appropriate values. Other properties are set to default values. (See model reference pages for information about default property values.)

You can specify other values for model properties at model creation using the Name,Value pair syntax of the model-creation command. In this syntax, you specify the name of the property you want to set, followed by the value. You can set multiple property values in one command. For example, assign a transport delay and input and output names to a new transfer function model.

H = tf(1,[1 10],'IODelay',6.5,'InputName','torque','OutputName','velocity')
H =
 
  From input "torque" to output "velocity":
                  1
  exp(-6.5*s) * ------
                s + 10
 
Continuous-time transfer function.

Some property values are reflected in the model display, such as the input and output names. You can use Name,Value pair syntax when creating any type of model.

Examine and Change Properties of an Existing Model

Load an existing state-space (ss) model.

load(fullfile(matlabroot,'examples','control','PadeApproximation1.mat'),'sys')
sys
sys =
 
  A = 
         x1    x2
   x1  -1.5  -0.1
   x2     1     0
 
  B = 
       u1
   x1   1
   x2   0
 
  C = 
        x1   x2
   y1  0.5  0.1
 
  D = 
       u1
   y1   0
 
  (values computed with all internal delays set to zero)

  Output delays (seconds): 1.5 
  Internal delays (seconds): 3.4 
 
Continuous-time state-space model.

The display shows that sys is a state-space model, and includes some of the property values of sys. To see all properties of sys, use the get command.

get(sys)
                A: [2x2 double]
                B: [2x1 double]
                C: [0.5000 0.1000]
                D: 0
                E: []
           Scaled: 0
        StateName: {2x1 cell}
        StateUnit: {2x1 cell}
    InternalDelay: 3.4000
       InputDelay: 0
      OutputDelay: 1.5000
               Ts: 0
         TimeUnit: 'seconds'
        InputName: {''}
        InputUnit: {''}
       InputGroup: [1x1 struct]
       OutputName: {''}
       OutputUnit: {''}
      OutputGroup: [1x1 struct]
            Notes: [0x1 string]
         UserData: []
             Name: ''
     SamplingGrid: [1x1 struct]

Use dot notation to access the values of particular properties. For example, display the A matrix of sys.

Amat = sys.A
Amat = 2×2

   -1.5000   -0.1000
    1.0000         0

Dot notation also lets you change the value of individual model properties.

sys.InputDelay = 4.2;
sys.InputName = 'thrust';
sys.OutputName = 'velocity';

When you must change multiple property values at the same time to preserve the validity of the model, such as changing the dimensions of the state-space matrices, you can use the set command. For example, create a 1-state state-space model, and then replace the matrices with new values representing a 2-state model.

sys2 = rss(1);
Anew = [-2, 1; 0.5 0];
Bnew = [1; -1];
Cnew = [0, -0.4];
set(sys2,'A',Anew,'B',Bnew,'C',Cnew)
sys2
sys2 =
 
  A = 
        x1   x2
   x1   -2    1
   x2  0.5    0
 
  B = 
       u1
   x1   1
   x2  -1
 
  C = 
         x1    x2
   y1     0  -0.4
 
  D = 
           u1
   y1  0.3426
 
Continuous-time state-space model.

Changing certain properties, such as Ts or TimeUnit, can cause undesirable changes in system behavior. See the property descriptions in the model reference pages for more information.

Related Topics