是否有类似于style的工具来格式化m文件中的matlab代码?
在最新版本的MATLAB中,您可以使用MATLAB Editor API以编程方式使用"Smart缩进"工具。
作为一个例子,假设您想修复特定目录中包含的所有m文件的缩进:
%# gel list of m-files in a directory
BASE_DIR = 'c:pathtofolder';
files = dir( fullfile(BASE_DIR,'*.m') );
files = {files.name};
for i=1:numel(files)
%# open file in editor, apply smart indentation, save and close
doc = matlab.desktop.editor.openDocument( fullfile(BASE_DIR,files{i}) );
doc.smartIndentContents;
doc.save;
doc.close;
end
请记住,您可以在Matlab的编辑器中选择文本并按Ctrl+I
自动缩进。(另外,使用Ctrl+A
选择所有文本)