Contenido principal

Simulink.sdi.getDataAccess

Get settings for streaming signal data to MATLAB callback function during simulation

Since R2026a

    Description

    dataAccess = Simulink.sdi.getDataAccess(block,portIndex) returns a structure with fields that indicate the data access settings for a signal identified by the block path or handle and the port index.

    example

    dataAccess = Simulink.sdi.getDataAccess(portHandle) returns the data access settings for a signal specified using the output port handle.

    example

    dataAccess = Simulink.sdi.getDataAccess(lineHandle) returns the data access settings for a signal specified using the line handle.

    example

    Examples

    collapse all

    Mark the signal connected to the first output port of the Gain block in the model myModel for logging.

    Simulink.sdi.markSignalForStreaming("myModel/Gain",1,"on");

    To configure data access settings for the logged signal, use the Simulink.sdi.setDataAccess function with the block path and port index of the source block. For example, specify these settings:

    • Enable streaming signal data to a MATLAB® function during simulation.

    • Use the callback function named myCallback as the MATLAB function that receives signal data during simulation.

    • Specify a function parameter of "1" to identify which signal data the function receives.

    • Include simulation time.

    Simulink.sdi.setDataAccess("myModel/Gain",1,Enable=true,...
        CallbackFunction="myCallback",FunctionParameter="1",IncludeTime=true)

    View the data access settings using the Simulink.sdi.getDataAccess function.

    dataAccess = Simulink.sdi.getDataAccess("myModel/Gain",1)
    dataAccess = struct with fields:
                   Enable: 1
         CallbackFunction: 'myCallback'
        FunctionParameter: '1'
              IncludeTime: 1

    Use the get_param function to get the port handles for the source block of your signal of interest. For example, get the port handle for the output port of the Gain block in the model myModel.

    portHandles = get_param("myModel/Gain","PortHandles");
    myPortHandle = portHandles.Outport;

    Use the port handle to mark the desired signal for logging.

    Simulink.sdi.markSignalForStreaming(myPortHandle,"on");

    To configure data access settings for the logged signal, use the Simulink.sdi.setDataAccess function with the port handle of the source block. For example, specify these settings:

    • Enable streaming signal data to a MATLAB function during simulation.

    • Use the callback function named myCallback as the MATLAB function that receives signal data during simulation.

    • Specify a function parameter of "1" to identify which signal data the function receives.

    • Include simulation time.

    Simulink.sdi.setDataAccess(myPortHandle,Enable=true,...
        CallbackFunction="myCallback",FunctionParameter="1",IncludeTime=true)

    View the data access settings using the Simulink.sdi.getDataAccess function.

    dataAccess = Simulink.sdi.getDataAccess(myPortHandle)
    dataAccess = struct with fields:
                   Enable: 1
         CallbackFunction: 'myCallback'
        FunctionParameter: '1'
              IncludeTime: 1

    Use the get_param function to get the line handle for your signal of interest. For example, get the handle for the signal line connected to the output port of the Gain block in the model myModel.

    lineHandles = get_param("myModel/Gain","LineHandles");
    myLineHandle = lineHandles.Outport;

    Use the line handle to mark the desired signal for logging.

    Simulink.sdi.markSignalForStreaming(myLineHandle,"on");

    To configure data access settings for the logged signal, use the Simulink.sdi.setDataAccess function with the line handle. For example, specify these settings:

    • Enable streaming signal data to a MATLAB function during simulation.

    • Use the callback function named myCallback as the MATLAB function that receives signal data during simulation.

    • Specify a function parameter of "1" to identify which signal data the function receives.

    • Include simulation time.

    Simulink.sdi.setDataAccess(myLineHandle,Enable=true,...
        CallbackFunction="myCallback",FunctionParameter="1",IncludeTime=true)

    View the data access settings using the Simulink.sdi.getDataAccess function.

    dataAccess = Simulink.sdi.getDataAccess(myLineHandle)
    dataAccess = struct with fields:
                   Enable: 1
         CallbackFunction: 'myCallback'
        FunctionParameter: '1'
              IncludeTime: 1

    Input Arguments

    collapse all

    Source block path or handle for the block with the desired signal connected to one of its output ports, specified as a string or character vector. To get the path or handle of the currently selected block, use the gcb or gcbh function, respectively.

    Example: "myModel/Gain"

    Output port index of the source block connected to the signal of interest, specified as a positive integer.

    Example: 1

    Port handle of the output port of the source block connected to the signal of interest, specified as a handle.

    Use the get_param function with the "PortHandles" option to get port handles.

    Example: myPortHandles.Outport(1)

    Line handle for the signal of interest, specified as a handle.

    Use the get_param function with the "LineHandles" option to get line handles.

    Example: myLineHandles.Outport(1)

    Output Arguments

    collapse all

    Data access settings, returned as a structure with these fields:

    • Enable — Whether signal data streams to a MATLAB function during simulation

    • CallbackFunction — Name of MATLAB function that receives signal data during simulation

    • FunctionParameter — Parameter used to identify data source in the callback function

    • IncludeTime — Whether simulation time data is sent to callback function

    Version History

    Introduced in R2026a