Matlab代码格式类似于AStyle?

Che*_*riy 7 ide matlab coding-style code-formatting

有没有类似于AStyle的工具来格式化m文件中的matlab代码?

Amr*_*mro 5

在最新版本的MATLAB中,您可以使用MATLAB Editor API以编程方式使用"Smart Indent"工具.

例如,假设您要修复特定目录中包含的所有M文件的缩进:

%# gel list of m-files in a directory
BASE_DIR = 'c:\path\to\folder';
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
Run Code Online (Sandbox Code Playgroud)

  • 感谢智能代码段.我也想格式化空格 (4认同)

cyb*_*org 1

请记住,您可以在 Matlab 编辑器中选择文本,然后Ctrl+I按 自动缩进。(另外,使用Ctrl+A来选择所有文本。)