Main Content

sldiagviewer.Comparator.displayResult

Display differences in diagnostic details of model operations

Since R2025a

    Description

    sldiagviewer.Comparator.displayResult(comparison) displays the results of the comparison between diagnostic details from two model operations, obtained using the sldiagviewer.Comparator.compare and sldiagviewer.Comparator.compareWithBaseline functions. The results show the newly added diagnostic messages and the count of diagnostic messages that are added or removed.

    example

    Examples

    collapse all

    Open the model DiagnosticDemo.

    model = "DiagnosticDemo";
    open_system(model);

    Create a sldiagviewer.DiagnosticReceiver object. This object receives the diagnostic details from all model operations until the object is deleted.

    rx1 = sldiagviewer.DiagnosticReceiver;

    Simulate the model.

    sim(model);

    Get the diagnostic details generated during model simulation by using the DiagnosticReceiver object rx1.

    stage1 = getDiagnostics(rx1);

    Delete rx1 and then create a new DiagnosticReceiver object rx2. This prevents diagnostic details from previous simulations from being carried over to rx2. Otherwise, rx2 also includes diagnostic details received in rx1.

    delete(rx1);
    rx2 = sldiagviewer.DiagnosticReceiver;

    Add a few sample warnings to the model by setting the StartFcn model callback.

    setWarningCmd = sprintf([
        'for i = 1:5\n', ...
            'sldiagviewer.reportWarning("Sample warning.");\n', ...
        'end']);
    set_param(model,"StartFcn",setWarningCmd);

    Simulate the model again.

    sim(model);
    Warning: Sample warning.
    
    Warning: Sample warning.
    
    Warning: Sample warning.
    
    Warning: Sample warning.
    
    Warning: Sample warning.
    

    Get the diagnostics generated during model simulation by using the DiagnosticReceiver object rx2.

    stage2 = getDiagnostics(rx2);

    Delete the DiagnosticReceiver object rx2.

    delete(rx2);

    Compare the diagnostics from the two simulation stages. When you compare the diagnostics, a structure stores the details of the diagnostics that are added or removed in stage2 as compared to stage1.

    comparison = sldiagviewer.Comparator.compare(stage1,stage2)
    comparison = struct with fields:
          DiagnosticsAdded: [1×1 struct]
        DiagnosticsRemoved: [1×1 struct]
    
    

    Display the comparison results.

    sldiagviewer.Comparator.displayResult(comparison)
    Diagnostics Added
    Messages: 
    Sample warning.
    Sample warning.
    Sample warning.
    Sample warning.
    Sample warning.
    Errors: 0
    Warnings: 5
    Diagnostics Removed
    Errors: 0
    Warnings: 0
    

    The results show that five new warnings are added and no diagnostic messages are removed. Displaying the results also shows the newly added diagnostic messages.

    Convert the comparison structure to a JSON format.

    comp_json = sldiagviewer.Comparator.convertToJson(comparison)
    comp_json = 
    '{"DiagnosticsAdded":{"Message":["Sample warning.","Sample warning.","Sample warning.","Sample warning.","Sample warning."],"Errors":0,"Warnings":5},"DiagnosticsRemoved":{"Errors":0,"Warnings":0}}'
    

    Input Arguments

    collapse all

    Diagnostics that are added or removed when comparing diagnostic details between two model operations using the sldiagviewer.Comparator.compare function, specified as a structure.

    Data Types: struct

    Version History

    Introduced in R2025a