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

 채택된 답변

Jan
Jan 2013년 9월 17일

1 개 추천

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

추가 답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 17일
편집: Azzi Abdelmalek 2013년 9월 17일

0 개 추천

Use fgetl function to read your files and save them in a cell array. Concatenate your variables then save the result in one file.
% or
!copy file1.m+file2.m new_file3.m

댓글 수: 1

Jan
Jan 2013년 9월 17일
I think, the OP means the standard indentation of M-code.

댓글을 달려면 로그인하십시오.

Image Analyst
Image Analyst 2013년 9월 17일

0 개 추천

If you want to handle the opening and closing of the file(s) yourself, you can simply do Ctrl-A (to select all the text in the m-file), then type Ctrl-I (to properly indent everything). You can also use Ctrl-I to "fix" just the selected text (instead of everything) if you want.

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

태그

질문:

2013년 9월 17일

댓글:

2013년 11월 22일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by