Main Content

getDiagnostics

Get diagnostic details of model operation

Since R2025a

    Description

    diagMsg = getDiagnostics(receiver) gets the diagnostic details, such as diagnostic message, message ID, and severity, generated during a model run-time operation by using the sldiagviewer.DiagnosticReceiver object receiver.

    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 sldiagviewer.DiagnosticReceiver object rx1.

    stage1 = getDiagnostics(rx1)
    stage1=1×5 cell array
        {1×1 MSLDiagnostic}    {1×1 MSLDiagnostic}    {1×1 MSLDiagnostic}    {1×1 MSLDiagnostic}    {1×1 MSLDiagnostic}
    
    

    Delete the DiagnosticReceiver object rx1.

    delete(rx1);

    Input Arguments

    collapse all

    Diagnostic details receiver, specified as a sldiagviewer.DiagnosticReceiver object.

    Output Arguments

    collapse all

    Diagnostic details of model run-time operations, returned 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.

    Version History

    Introduced in R2025a