Does Matlab have the function to format script?

Just wondering if Matlab has the function to format script, e.g., automatically add a space after a comma, or add spaces before and after an "=" when I press semicolon at the end of a statement, or select a block of script to be formatted and press some button. Thanks.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 11 de Jun. de 2016

2 votos

No, MATLAB does not have that. Fortunately, David Varga recently mentioned releasing a beautifier; see https://github.com/davidvarga/MBeautifier

Más respuestas (4)

Azzi Abdelmalek
Azzi Abdelmalek el 10 de Jun. de 2016

14 votos

Select your code, then right click with your mouse, you will see all possibilities you have. For example (ctrl+i) which is smart indent

2 comentarios

zzzhhh
zzzhhh el 11 de Jun. de 2016
I didn't find any item in the context menu except smart indent that is related to code formatting as I mentioned in the question. Note that in my question the "format" does not refer to change of fonts, but more to proper addition of spaces and alignments.
Yash Mavare
Yash Mavare el 8 de En. de 2022
thank you

Iniciar sesión para comentar.

Image Analyst
Image Analyst el 8 de En. de 2022

6 votos

Type
control-a, to select all text in your editor window, then
control-i, to fix (properly align) the indenting of your lines of code.
Julian Hapke
Julian Hapke el 11 de Dic. de 2023
Here's a MATLAB snippet that depends on the undocumented tree2str and mtree, but produces a reasonable result:
tree2str(mtree(FILENAME, '-file', '-comments'))

Categorías

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

Preguntada:

el 10 de Jun. de 2016

Respondida:

el 11 de Dic. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by