Matlab code formatting similar to AStyle? [closed]

旧街凉风 提交于 2019-12-20 14:12:50

问题


Is there any tool similar to AStyle to format matlab code in m-files?


回答1:


In recent versions of MATLAB, you can use the "Smart Indent" tool programmatically using the MATLAB Editor API.

As an example, say you want to fix indentation of all M-files contained in a specific directory:

%# 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



回答2:


Remember that you can select text in Matlab's editor and press Ctrl+I to auto-indent it. (Also , use Ctrl+A to select all the text.)



来源:https://stackoverflow.com/questions/7861006/matlab-code-formatting-similar-to-astyle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!