Open the model DiagnosticDemo.
Create a sldiagviewer.DiagnosticReceiver object. This object receives the diagnostic details from all model operations until the object is deleted.
Simulate the model.
Get the diagnostic details generated during model simulation by using the DiagnosticReceiver object 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.
Add a few sample warnings to the model by setting the StartFcn model callback.
Simulate the model again.
Get the diagnostics generated during model simulation by using the DiagnosticReceiver object rx2.
Delete the DiagnosticReceiver object 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 = struct with fields:
DiagnosticsAdded: [1×1 struct]
DiagnosticsRemoved: [1×1 struct]
Display the comparison results.
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 =
'{"DiagnosticsAdded":{"Message":["Sample warning.","Sample warning.","Sample warning.","Sample warning.","Sample warning."],"Errors":0,"Warnings":5},"DiagnosticsRemoved":{"Errors":0,"Warnings":0}}'