Is there any tool similar to AStyle to format matlab code in m-files?
Matlab code formatting similar to AStyle? [closed]
Asked Answered
I know it is an old question, but if you are interested, see my answer on this question: #23961322 –
Baggage
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
thanks for the smart snippet. I'd like to format whitespace also –
Litton
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.)
© 2022 - 2024 — McMap. All rights reserved.