Main Content

getResultsByName

Return signal comparison results based on signal name

Since R2022b

    Description

    diffSig = getResultsByName(diffRes,sigName) returns the signal comparison result for the signal named sigName in the run comparison results object diffRes.

    The output of the function getResultsByName depends on the signal that is being compared.

    • If the result that corresponds to sigName is a real, scalar signal, then diffSig is a Simulink.sdi.DiffSignalResult object.

    • If the result that corresponds to sigName is a complex signal, a multidimensional signal, or a bus, then diffSig is an array of Simulink.sdi.DiffSignalResult objects. The size of the array corresponds to characteristics of the comparison result.

    example

    Examples

    collapse all

    Load the Simulation Data Inspector session file getResultsByNameData. The file contains data logged from two simulations of the model getResultsByNameModel, which logs data for five signals.

    Simulink.sdi.load("getResultsByNameData.mldatx");

    Access the run IDs for the two runs loaded from the file.

    runIDs = Simulink.sdi.getAllRunIDs;
    baselineID = runIDs(end-1);
    comparedToID = runIDs(end);

    Compare the two runs.

    diffResult = Simulink.sdi.compareRuns(baselineID,comparedToID);

    Use the function getResultsByName to access comparison results for the signal ScalarOut.

    compareSig = getResultsByName(diffResult,"ScalarOut")
    compareSig = 
      DiffSignalResult with properties:
    
                 Name: 'ScalarOut'
               Status: WithinTolerance
              AlignBy: 'Path'
            SignalID1: 4872
            SignalID2: 4952
        MaxDifference: 0
                Sync1: [1x1 timeseries]
                Sync2: [1x1 timeseries]
                 Diff: [1x1 timeseries]
    
    

    Load the Simulation Data Inspector session file getResultsByNameData. The file contains data logged from two simulations of the model getResultsByNameModel, which logs data for five signals, including the complex signal ComplexOut.

    Simulink.sdi.load("getResultsByNameData.mldatx");

    Access the run IDs for the two runs loaded from the file.

    runIDs = Simulink.sdi.getAllRunIDs;
    baselineID = runIDs(end-1);
    comparedToID = runIDs(end);

    Compare the two runs.

    diffResult = Simulink.sdi.compareRuns(baselineID,comparedToID);

    Use the function getResultsByName to access comparison results for the complex signal ComplexOut.

    compareComplex = getResultsByName(diffResult,"ComplexOut")
    compareComplex=1×2 DiffSignalResult array with properties:
        Name
        Status
        AlignBy
        SignalID1
        SignalID2
        MaxDifference
        Sync1
        Sync2
        Diff
        Options
    
    

    You can also use the function getResultsByName to access comparison results for the real or imaginary parts of the signal by specifying (real) or (imag) as part of the signal name.

    compareComplexReal = getResultsByName(diffResult,"ComplexOut (real)")
    compareComplexReal = 
      DiffSignalResult with properties:
    
                 Name: 'ComplexOut (real)'
               Status: WithinTolerance
              AlignBy: 'Path'
            SignalID1: 1661
            SignalID2: 1741
        MaxDifference: 0
                Sync1: [1x1 timeseries]
                Sync2: [1x1 timeseries]
                 Diff: [1x1 timeseries]
    
    

    Load the Simulation Data Inspector session file getResultsByNameData. The file contains data logged from two simulations of the model getResultsByNameModel, which logs data for five signals, including two multidimensional signals: SmallMux and LargeMux.

    Simulink.sdi.load("getResultsByNameData.mldatx");

    Access run IDs for the two runs loaded from the file.

    runIDs = Simulink.sdi.getAllRunIDs;
    baselineID = runIDs(end-1);
    comparedToID = runIDs(end);

    Compare the two runs.

    diffResult = Simulink.sdi.compareRuns(baselineID,comparedToID);

    Use the function getResultsByName to access comparison results for LargeMux and SmallMux. By default, when you compare runs that contain signals with multidimensional sample values, the Simulation Data Inspector expands the signal to channels and compares the channels. For more information, see Analyze Multidimensional Signal Data.

    compareLargeMux = getResultsByName(diffResult,"LargeMux")
    compareLargeMux=1×5 DiffSignalResult array with properties:
        Name
        Status
        AlignBy
        SignalID1
        SignalID2
        MaxDifference
        Sync1
        Sync2
        Diff
        Options
    
    
    compareSmallMux = getResultsByName(diffResult,"SmallMux")
    compareSmallMux=1×2 DiffSignalResult array with properties:
        Name
        Status
        AlignBy
        SignalID1
        SignalID2
        MaxDifference
        Sync1
        Sync2
        Diff
        Options
    
    

    You can access comparison results for an element within a multidimensional signal using the index of the element within the logged signal. For example, get comparison results for the fourth element of the LargeMux signal.

    compareElement = compareLargeMux(4)
    compareElement = 
      DiffSignalResult with properties:
    
                 Name: 'LargeMux(4)'
               Status: WithinTolerance
              AlignBy: 'Path'
            SignalID1: 4432
            SignalID2: 4436
        MaxDifference: 0
                Sync1: [1x1 timeseries]
                Sync2: [1x1 timeseries]
                 Diff: [1x1 timeseries]
    
    

    Load the Simulation Data Inspector session file getResultsByNameData. The file contains data logged from two simulations of the model getResultsByNameModel, which logs data for five signals, including a bus.

    Simulink.sdi.load("getResultsByNameData.mldatx");

    Access the run IDs for the two runs loaded from the file.

    runIDs = Simulink.sdi.getAllRunIDs;
    baselineID = runIDs(end-1);
    comparedToID = runIDs(end);

    Compare the two runs.

    diffResult = Simulink.sdi.compareRuns(baselineID,comparedToID);

    Use the function getResultsByName to access the comparison results for BusOut.

    compareBus = getResultsByName(diffResult,"BusOut")
    compareBus=1×4 DiffSignalResult array with properties:
        Name
        Status
        AlignBy
        SignalID1
        SignalID2
        MaxDifference
        Sync1
        Sync2
        Diff
        Options
    
    

    You can also get comparison results for bus elements. Use the function getResultsByName to access the comparison results for the signal Constant 4 inside the bus BusOut.

    compareConst4 = getResultsByName(diffResult,"BusOut.Constant_4")
    compareConst4 = 
      DiffSignalResult with properties:
    
                 Name: 'BusOut.Constant_4'
               Status: WithinTolerance
              AlignBy: 'Path'
            SignalID1: 37
            SignalID2: 117
        MaxDifference: 0
                Sync1: [1x1 timeseries]
                Sync2: [1x1 timeseries]
                 Diff: [1x1 timeseries]
    
    

    Input Arguments

    collapse all

    Run comparison results that contain the signal result you want to access, specified as a Simulink.sdi.DiffRunResult object.

    Name of the signal in the run comparison results, specified as a character vector or string.

    To access a bus element, specify the path to the element through the hierarchy of the bus. For example, to access comparison results for the signal Sine inside the bus BusOut, specify sigName as "BusOut.Sine".

    sineRes = getResultsByName(diffRes,"BusOut.Sine");

    To access only the real or imaginary result for a complex signal, append the signal name with either (real) or (imag). For example, to access the comparison results for the imaginary part of the complex signal ComplexOut, specify sigName as "ComplexOut (imag)".

    imagRes = getResultsByName(diffRes,"ComplexOut (imag)");

    Data Types: char | string

    Output Arguments

    collapse all

    Comparison results for specified name, returned as a Simulink.sdi.DiffSignalResult object or an array of Simulink.sdi.DiffSignalResult objects.

    The type of output returned by getResultsByName depends on the sigName input.

    sigName InputdiffSig Result
    Uniquely named scalar signal

    Simulink.sdi.DiffSignalResult object

    One of N scalar signals with the same name

    1×N array of Simulink.sdi.DiffSignalResult objects

    Complex signal

    1×2 array of Simulink.sdi.DiffSignalResult objects that contain the real and imaginary results

    Vector or matrix signal with N elements

    1×N array of Simulink.sdi.DiffSignalResult objects

    Bus

    1×N array of Simulink.sdi.DiffSignalResult objects, where N is the number of elements in the bus

    Note

    If you specify a name for sigName that is not in the run comparison results, then the function returns an empty array.

    Version History

    Introduced in R2022b