Main Content

findSignal

Find index of signals in Signals property vector

    Description

    sigIdx = findSignal(mdlInfo,blkPath) creates a vector of numeric indices corresponding to the Signals vector of the model logging override settings object mdlInfo for the signals specified by the block path blkPath.

    • To find a single instance of a signal within a referenced model, use a Simulink.BlockPath object or a cell array with a full path.

    • To find all instances of a signal within a referenced model, use a character vector with the relative path of the signal within the referenced model.

    • To find a logged chart signal within a Stateflow® chart, use a Simulink.BlockPath object and set the SubPath property to the name of the Stateflow chart signal.

    example

    sigIdx = findSignal(mdlInfo,blkPath, portIdx) finds the indices of the output signal for the specified port.

    Do not use the portIdx argument for Stateflow chart signals. For an example that uses the findSignal function with a Stateflow chart, see Override Logging Properties with the Command-Line API (Stateflow).

    Examples

    collapse all

    You can use the findSignal function to find the index of a signal in a model logging override object.

    Open the IterativeCounter project. The project opens the CounterSystem model at startup. The CounterSystem model logs four signals. Three of the logged signals are in this top model. The fourth signal is in the referenced model named CounterAlgorithm.

    openProject("IterativeCounter");

    Create a model logging override object with override settings for each logged signal in the model.

    mdl = 'CounterSystem';
    mdlInfo = Simulink.SimulationData.ModelLoggingInfo.createFromModel(mdl)
    mdlInfo = 
      ModelLoggingInfo with properties:
    
                         Model: 'CounterSystem'
                   LoggingMode: 'OverrideSignals'
        LogAsSpecifiedByModels: {}
                       Signals: [1×4 Simulink.SimulationData.SignalLoggingInfo]
    
    

    The Controls bus is the output of a Subsystem block in the CounterSystem model. Using the block path to the Subsystem block, you can find the index of the Controls bus in the Signals property of the model logging override object mdlInfo.

    blkPath = 'CounterSystem/Subsystem';
    sigIdx = findSignal(mdlInfo,blkPath)
    sigIdx = 
    3
    

    You can also use the findSignal function to find a signal in a specific instance of a referenced model. For example, the InnerCount signal is the output of a For Each Subsystem block in the CounterAlgorithm model. Using a block path to the For Each Subsystem block in the CounterAlgorithm model, you can find the index of the InnerCount signal in the Signals property of the model logging override object mdlInfo.

    blkPathRef = {'CounterSystem/Model',...
        'CounterAlgorithm/For Each Subsystem'};
    sigIdxRef = findSignal(mdlInfo,blkPathRef)
    sigIdxRef = 
    4
    

    Input Arguments

    collapse all

    Model logging override object, specified as a Simulink.SimulationData.ModelLoggingInfo object.

    Source block to search, specified as a character vector, cell array of character vectors, or Simulink.Blockpath object.

    Index of the output port to search, specified as a positive integer.

    Version History

    Introduced in R2012b