Command to view the Diagnostic Viewer in the Matlab Command Window
53 次查看(过去 30 天)
显示 更早的评论
Is there any command that I can use so I get the output from the Diagnostic Viewer displayed in the Matlab command vindow when for example when i load the simulink model I want to see all the warnings in the command window.
回答(1 个)
Payas Bahade
2019-12-24
Hi Ravi,
If any errors/warnings occur during simulations, they are displayed in command window itself. These errors/warnings are same as what is displayed in 'Diagnostic Viewer' of Simulink.
Errors/warnings encountered during simulation can also be accessed from Simulation Metadata. For this, in ‘Configuration Parameters > Data Import/Export > Save to workspace or file’ enable ‘Single simulation output’ and this variable (for eg. ‘out’) stores all simulation data and can be accessed from MATLAB workspace.
Use below command to view diagnostic data of simulation which is stored in variable 'out':
out.getSimulationMetadata.ExecutionInfo.WarningDiagnostics.Diagnostic
You can also log the Diagnostic messages into a text file by using below syntaxes:
sldiagviewer.diary
Hope this helps!
2 个评论
Michael Jeschke
2022-12-16
编辑:Michael Jeschke
2022-12-16
This does not work for me (I am on version 2019b).
> If any errors/warnings occur during simulations, they are displayed in command window itself.
> These errors/warnings are same as what is displayed in 'Diagnostic Viewer' of Simulink.
Unfortunately it is not at all the same.
I have a Simulink model with a Stateflow state chart, and a compile time error or a runtime error happens due to an error in my Matlab function that exists as m-file and is invoked from a state transition.
Now when I simulate in "GUI mode" (i.e. after graphically opening the Simulink model and clicking "Run" button) all is fine, I get meaningful error messages in the Diagnostic Viewer window like:
In case of a runtime error:
- "Attempted to access index 100 of an array with smaller dimension sizes. The valid index range is 1 to 35. This error will stop the simulation."
In case of a compile time error:
- Undefined function or variable 'dfgdfg'. Function 'write_INPUTS_to_ASCII_file.m' (#1194.9217.9223), line 153, column 1: "dfgdfg"
However, when I start the same simulation from within an m-script or m-function via "sim" command, then I get a fully useless error message on the console that only points to the line of the script from which I called "sim", like (in case of compile time error):
- Error using DSM_sim_all_subroutine (line 185)
- Error due to multiple causes.
- Error in DSM_sim_all (line 131)
- evalin('base', 'DSM_sim_all_subroutine')
In case of runtime error, I still do get the message on the console, fortunately:
- Attempted to access index 100 of an array with smaller dimension sizes. The valid index range is 1 to 35. This error will stop the simulation.
That line 185 mentioned above is the line of my wrapper file from where I make the "sim" call. So this error message is absolutely useless for me. Moreover, note that:
- In case of the runtime error, no Diagnostic Viewer window pops up at all if I call "sim" from within that m-file.
- In case of the compile time error, a Diagnostic Viewer window pops up shortly but then disappears again, and the precious info generated in that Diagnostic Viewer window gets lost before I can read it!
This is a bug.
If I then call
sldiagviewer.diary
I only get a completely empty file diary.txt (0 bytes).
Also the content of
out.getSimulationMetadata.ExecutionInfo.WarningDiagnostics.Diagnostic
or
out.getSimulationMetadata.ExecutionInfo.ErrorDiagnostic.Diagnostic
does not contain the info from the Diagnostic Viewer window.
So how can I get the info from the Diagnostic Viewer window if that info only pops up shortly before it disappears, or does not show up at all in "non-GUI mode"?
Remember, my use-case is that I call "sim" not from the console but from within a "wrapper" m-file (a script running in base workspace) that makes multiple calls of "sim" within a while loop.
Michael Jeschke
2022-12-16
Update: About
sldiagviewer.diary:
I now found out that I can globally activate/deactivate the logging into "diary.txt" via
>> sldiagviewer.diary('on')
>> sldiagviewer.diary('off')
The compile time errors are logged in a meaningful way to "diary.txt" when this is set to 'on'.
The runtime errors however are not.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Configure and View Diagnostics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!