Search code examples
matlabwarningsstatic-analysisremote-execution

How to display static analysis warnings in MATLAB?


I've noticed the MATLAB editor will often show quite helpful warnings for ".m" files. As I tend to run my MATLAB code remotely I prefer not to use the MATLAB editor, instead keeping open a long running emacs session. It would be great if these warnings could be printed out when running a script, perhaps if some setting was enabled (I could imagine not wanting to do that by default for performance). Is this possible?


Solution

  • I believe you're looking for checkcode. From the documentation:

    checkcode(filename) displays messages about filename that report potential problems and opportunities for code improvement. These messages are sometimes referred to as Code Analyzer messages. The line number in the message is a hyperlink that you can click to go directly to that line in the Editor. The exact text of the checkcode messages is subject to some change between versions.

    ...

    info = checkcode(___,'-struct') returns the information as an n-by-1 structure array, where n is the number of messages found.