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

 Respuesta aceptada

Jan
Jan el 17 de Sept. de 2013

1 voto

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

Más respuestas (2)

Azzi Abdelmalek
Azzi Abdelmalek el 17 de Sept. de 2013
Editada: Azzi Abdelmalek el 17 de Sept. de 2013

0 votos

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 comentario

Jan
Jan el 17 de Sept. de 2013
I think, the OP means the standard indentation of M-code.

Iniciar sesión para comentar.

Image Analyst
Image Analyst el 17 de Sept. de 2013

0 votos

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.

Categorías

Más información sobre File Operations en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 17 de Sept. de 2013

Comentada:

el 22 de Nov. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by