Contenuto principale

delete

Delete sldiagviewer.DiagnosticReceiver object

Since R2025a

    Description

    delete(receiver) deletes 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 warning to the model by setting the StartFcn model callback.

    setWarningCmd = sprintf(...
        'sldiagviewer.reportWarning("Sample warning 1");');
    set_param(model,"StartFcn",setWarningCmd);

    Simulate the model.

    sim(model);
    Warning: Sample warning 1
    

    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 2");\n', ...
        'end']);
    set_param(model,"StartFcn",setWarningCmd);

    Simulate the model again.

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

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

    stage2 = getDiagnostics(rx2);

    Delete the DiagnosticReceiver object rx2 to close the current diagnostic stage.

    delete(rx2);

    Input Arguments

    collapse all

    Diagnostic details receiver to be deleted, specified as a sldiagviewer.DiagnosticReceiver object.

    Version History

    Introduced in R2025a