无需执行将所有 m 文件粘贴到一个以运行MLINT的繁琐(并且可能容易出错)任务,您还有其他一些选择...
如果您将所有文件都放在一个文件夹中,最简单的方法是转到当前文件夹浏览器,单击“操作”按钮
,然后选择“报告”>“代码分析器报告”。

这将打开一个新窗口,显示当前目录中每个 m 文件的 MLINT 结果:

如果您宁愿使用脚本自动执行该过程,而不必单击菜单选项,那么 MathWorks 文件交换(此处和此处)上的一些提交似乎在目录结构上递归地工作,而不仅仅是单个目录。
此外,这里有一些示例代码可以为单个目录执行您想要的操作:
dirData = dir; %# Get data on the current directory contents
fileIndex = ~[dirData.isdir]; %# Get an index for the files
fileNames = {dirData(fileIndex).name}; %# Get the file names
[~,~,ext] = cellfun(@fileparts,fileNames,... %# Get the file extensions
'UniformOutput',false);
mFileIndex = strcmp(ext,'.m'); %# Get an index for the m-files
cellfun(@mlint,fileNames(mFileIndex)); %# Run MLINT on each m-file
您可以通过这种方式扩展文件名(和路径)的集合,以便在目录树上递归操作,然后在您收集的结果文件集上运行 MLINT。