Main Content

mlint

(Not recommended) Check MATLAB code files for possible problems

mlint is not recommended. Use checkcode instead.

For information on using the graphical user interface to the Code Analyzer, see Check Code for Errors and Warnings Using the Code Analyzer.

Description

mlint(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 a message is a hyperlink that you can click to go directly to that line in the Editor. The exact text of the mlint messages is subject to some change between versions.

If filename specifies multiple files, MATLAB® displays information for each file.

mlint(filename,'-config=settings.txt') overrides the default active settings file with the settings that enable or suppress messages as indicated in the specified settings.txt file.

Note

When using this syntax, you must specify the full path to the settings.txt file specified with the -config option.

For information about creating a settings.txt file, see Save and Reuse Code Analyzer Message Settings. If you specify an invalid file, mlint returns a message indicating that it cannot open or read the file you specified. In that case, mlint uses the factory default settings.

mlint(filename,'-config=factory') ignores all settings files and uses the factory default preference settings.

inform=mlint(filename,'-struct') returns the information in a structure array whose length is the number of messages found. The structure has these fields.

  • message — Message describing the potential code issue identified during code analysis.

  • line — Vector of file line numbers to which the message refers.

  • column — Two-column array of file columns (column extents) to which the message applies. The first column of the array specifies the column in the Editor where the message begins. The second column of the array specifies the column in the Editor where the message ends. There is one row in the two-column array for each occurrence of a message.

If you specify multiple filenames as input, inform contains a cell array of structures.

msg=mlint(filename,'-string') returns the information as the character vector msg. If you specify multiple filenames as input, msg contains information for each file, separated by 10 equal sign characters (=), a space, the filename, a space, and 10 equal sign characters.

If you omit the -struct or -string argument and you specify an output argument, the default behavior is -struct. If you omit the argument and there are no output arguments, the default behavior is to display the information to the command line.

[inform,filepaths]=mlint(filename) additionally returns filepaths, the absolute paths to the filenames, in the same order as in filename.

inform=mlint(filename,'-id') returns the message ID, where ID is a character vector of the form ABC.... When returned to a structure, the output also has the id field, which is the ID associated with the message.

inform=mlint(filename,'-fullpath') assumes that the input filenames are absolute paths so that mlint does not try to locate them.

inform=mlint(filename,'-notok') checks all lines in filename, even those lines that end with the mlint suppression directive, %#ok.

mlint(filename,'-cyc') displays the McCabe complexity (also referred to as cyclomatic complexity) of each function in the file. Higher McCabe complexity values indicate higher complexity, and evidence suggests that programs with higher complexity values are more likely to contain errors. Frequently, you can lower the complexity of a function by dividing it into smaller, simpler functions. In general, lower complexity values indicate programs that are easier to understand and modify. You may want to split up programs that have a complexity rating over 10.

mlint(filename,'-codegen') enables code generation messages for display in the Command Window.

Input Arguments

collapse all

Name of file, specified as a string array, character vector, or cell array of character vectors.

Tips

Extended Capabilities

Version History

Introduced before R2006a

See Also

|