Main Content

simscape.instrumentation.Variable

Container for Simscape variable logging information

Since R2024a

    Description

    simscape.instrumentation.Variable objects store variable logging information during simulation. simscape.instrumentation.Variable objects contain information about the source block and the timeseries values for the Simscape variable.

    Creation

    Simulating a model that has variables marked for logging creates one or more simscape.instrumentation.Variable objects.

    Properties

    expand all

    Block path of source block for Variable object, specified as a Simulink.SimulationData.BlockPath object.

    Logged time and data specified as either a timeseries object or timetable object.

    Name of Variable object to use for name-based access, specified as a string or character vector.

    Object Functions

    Examples

    collapse all

    1. To open the model, enter:

      openExample('simscape/PermanentMagnetDCMotorExample')

    2. Each block has a default variable table that you can retrieve and modify. To get the default variable table for the Load Torque block, enter:

      table1 = simscape.instrumentation.defaultVariableTable('PermanentMagnetDCMotor/Load Torque');

    3. To select the t variable for logging, enter:

      table1("t").Logging = true;

    4. To set table1 as the variable table for the Load Torque block, enter:

      simscape.instrumentation.setVariableTable('PermanentMagnetDCMotor/Load Torque',table1);

    5. After you run the model, Simscape stores the logged data in the Simulink.SimulationData.Dataset workspace variable named logsout. To run the model and view the logsout variable, enter:

      sim('PermanentMagnetDCMotor')
      logsout
      logsout = 
      
      Simulink.SimulationData.Dataset 'logsout' with 1 element
      
                                 Name          BlockPath                          
                                 ____________  __________________________________ 
          1  [1x1 Variable]      Motor Torque  PermanentMagnetDCMotor/Load Torque
      
        - Use braces { } to access, modify, or add elements using index.

    6. To access the simscape.instrumentation.Variable object, enter:

      logsout{1}
      ans = 
      
        simscape.instrumentation.Variable
        Package: simscape.instrumentation
      
        Properties:
               Name: 't'
          BlockPath: [1×1 Simulink.SimulationData.BlockPath]
             Values: [1×1 timeseries]

    Version History

    Introduced in R2024a