MATLAB: Indent multiple matlab codes

ctrl+i

i want to indent multiple codes. is there a matlab function that open, indent, save and close a file (given its directory) ? do you have other suggestions for my problems ? thanks

Best Answer

folder = cd;
fileList = dir(fullfile(folder, '*.m'));
for iFile = 1:length(fileList)
aFile = fullfile(folder, fileList(iFile).name);
h = matlab.desktop.editor.openDocument(aFile);
h.smartIndentContents
h.save
h.close
end