Main Content

Access Logged Signals with Spaces and Newlines in Logged Names

This example shows how to log signals with logged names that contain spaces or newlines. Open the model SpacesNewlines. The model logs three signals that illustrate:

  • A signal with a name that contains a space

  • A signal with a name that contains a newline

  • An unnamed signal that originates on a block with a name that contains a newline

mdl = "SpacesNewlines";
open_system(mdl)

Simulate the model.

out = sim(mdl)
out = 
  Simulink.SimulationOutput:
                logsout: [1x1 Simulink.SimulationData.Dataset] 
                   tout: [51x1 double] 
                   yout: [1x1 Simulink.SimulationData.Dataset] 

     SimulationMetadata: [1x1 Simulink.SimulationMetadata] 
           ErrorMessage: [0x0 char] 

All logged data is returned as a single Simulink.SimulationData object in a variable named out. Contained in the SimulationData object, signal logging data is grouped in a Simulink.SimulationData.Dataset object with the default name logsout. Use dot notation to access the signal logging data. In the Dataset object, names are displayed with a space where the signal name contains a space or a newline. The unnamed signal has an empty character array as its name.

sigData = out.logsout
sigData = 
Simulink.SimulationData.Dataset 'logsout' with 3 elements

                         Name  BlockPath                  
                         ____  __________________________ 
    1  [1x1 Signal]      ''    SpacesNewlines/Sine  Wave2
    2  [1x1 Signal]      x y   SpacesNewlines/Sine Wave  
    3  [1x1 Signal]      a b   SpacesNewlines/Sine Wave1 

  - Use braces { } to access, modify, or add elements using index.

You can access a signal with a name that contains a space by name or by index. For example, use the get function to access the signal named x y.

get(sigData,"x y")
ans = 
  Simulink.SimulationData.Signal
  Package: Simulink.SimulationData

  Properties:
              Name: 'x y'
    PropagatedName: ''
         BlockPath: [1x1 Simulink.SimulationData.BlockPath]
          PortType: 'outport'
         PortIndex: 1
            Values: [1x1 timeseries]

You can also access a signal with a name that contains a newline by name or by index. To access the signal by name, use newline to concatenate a newline character between two strings.

sigName = ["a" + newline + "b"];
get(sigData,sigName)
ans = 
  Simulink.SimulationData.Signal
  Package: Simulink.SimulationData

  Properties:
              Name: 'a...'
    PropagatedName: ''
         BlockPath: [1x1 Simulink.SimulationData.BlockPath]
          PortType: 'outport'
         PortIndex: 1
            Values: [1x1 timeseries]

When a signal is unnamed, use indexing to access the signal.

sigData{3}
ans = 
  Simulink.SimulationData.Signal
  Package: Simulink.SimulationData

  Properties:
              Name: 'a...'
    PropagatedName: ''
         BlockPath: [1x1 Simulink.SimulationData.BlockPath]
          PortType: 'outport'
         PortIndex: 1
            Values: [1x1 timeseries]

See Also

Functions

Objects

Related Topics