Contenuto principale

sldiagviewer.DiagnosticReceiver.saveBaseline

Save diagnostic details as baseline

Since R2025a

    Description

    sldiagviewer.DiagnosticReceiver.saveBaseline(baselinePath,diagMsg) saves the diagnostic details diagMsg generated during a model operation as a baseline file baselinePath in JSON format. You can use the saved baseline file to compare diagnostic details with the diagnostic details from subsequent model operations in the same MATLAB® session, across different sessions, or even across different MATLAB versions. To get the diagnostic details diagMsg of a model operation use the getDiagnostics function.

    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;

    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.

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

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

    stage1 = getDiagnostics(rx1);

    Save the diagnostic details from the stage1 simulation as a baseline in a JSON file.

    sldiagviewer.DiagnosticReceiver.saveBaseline ...
    ("D:\Projects\Simulink\Systems\baseline_simulation.json",stage1)
    

    Baseline saved successfully.

    You can use the baseline file to compare the diagnostic details from subsequent model operations in the same MATLAB® session, across different sessions, or across different MATLAB® versions. For more information, see Compare Diagnostic Messages Between Model Simulations Programmatically

    Delete the DiagnosticReceiver object rx1.

    delete(rx1);

    Input Arguments

    collapse all

    Absolute path to the baseline file to be created, specified as a string scalar or character vector.

    Example: "D:\Projects\Simulink\Systems\baseline_simulation.json"

    Tip

    When saving a baseline, include a word in the filename such as "simulation" or "build" to identify the contents of the file for future comparisons.

    Data Types: string | char

    Diagnostic details of a model operation, specified as a cell array of MSLDiagnostic objects. An MSLDiagnostic object contains the diagnostic details, such as diagnostic message, message ID, and severity, generated during a model run-time operation.

    Data Types: cell

    Alternatives

    You can save a baseline using the Comparator available in the Diagnostic Viewer. For more information, see Compare Diagnostic Messages Between Model Simulations.

    Version History

    Introduced in R2025a