M-file code formatting tool

조회 수: 84 (최근 30일)
Yuriy Chesnokov
Yuriy Chesnokov 2011년 10월 22일
답변: Julian Hapke 2023년 12월 11일
Is there any similar to AStyle formatting tool for C/C++/C# languages which can beautify matlab m-file code?
Ctrl+I is too simple for my needs
  댓글 수: 2
Jan
Jan 2011년 10월 22일
To answer this, we have to know your needs.
Personally I prefer an indentation, which is as trivial as possible - simply eye-popping.
Yuriy Chesnokov
Yuriy Chesnokov 2011년 10월 22일
편집: Guillaume 2018년 11월 28일
the same as in AStyle
to convert some unreadable or unformatted code to uniform style
example:
[V,D]=eig(Kn);clear Kn;
V=sortrows([V' diag(D)],size(X,1)+1);V=flipud(V);
latent=V(:,end);
coeff= V(:,1:end-1)';
clear V;clear D;
to uniform:
[V, D] = eig(Kn);
clear Kn;
V = sortrows([V' diag(D)], size(X,1)+1);
V = flipud(V);
latent = V(:,end);
coeff = V(:,1:end-1)';
clear V;
clear D;

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

답변 (7개)

David Varga
David Varga 2016년 6월 6일
I know it is an old question, and I just put this here as an addition.
You could check: MBeautifier
I have just created it for personal use, it is a lightweight M-Script based tool that can be usable to format Matlab M-Code directly in the Matlab editor
  댓글 수: 5
hasan fawaz
hasan fawaz 2019년 7월 30일
I love you man :D Life Saver :D !
Ruben Lange
Ruben Lange 2020년 4월 28일
Hi David,
I know I am very late to this, but I don't really know how to add the root directory to my matlab path as you describe on the github page...
I also don't understand how to do the shortcuts part.
Could you (or someone else) help me with this?
Thanks in advance!
Ruben

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


Florian Schanda
Florian Schanda 2021년 3월 26일
Hi, there is https://github.com/florianschanda/miss_hit which can format code and much more.

Troy_Daniel
Troy_Daniel 2019년 11월 21일
I know this question is quite old, and there is already a solution for Maltab GUI Editor. However, I prefer to edit M-files with vim, I'm frustrated to find that there was no a proper solution for commandline usage. So I imlement one using C++, which achieve quite simple formatting. The code is available on Github https://github.com/TroyDanielFZ/Matlab-M-Source-Formator .
This answer is posted in case that someone else need this implement for editors like vim.

Brian Harris
Brian Harris 2022년 8월 23일
편집: Brian Harris 2022년 8월 23일
vscode has a pretty good matlab formater built in (formats on save). Underpinning the vscode plugin is a python script which you can run on the command line (matlab_formatter.py <matlab_file_name>)

Jan
Jan 2011년 10월 22일
Did you try the "Crimson Editor" or XEmacs already?
  댓글 수: 1
Yuriy Chesnokov
Yuriy Chesnokov 2011년 10월 22일
no, do they support matlab code formatting? as in my comments to your question above?

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


Narendra Kulkarni
Narendra Kulkarni 2014년 9월 29일
Hi, I am facing the same problem. There arent any good tools to beautify matlab code or are there?
  댓글 수: 2
Image Analyst
Image Analyst 2014년 9월 30일
편집: Image Analyst 2014년 9월 30일
I don't understand why control-I is not acceptable for you and Yuriy. What's wrong with the way it does it? It fixes the indenting, though it doesn't add spaces around operators such as = and +. Is that the problem?
Evgeny Mirkes
Evgeny Mirkes 2018년 1월 11일
편집: Evgeny Mirkes 2018년 1월 11일
Because indentation is not enough for beauty code.

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


Julian Hapke
Julian Hapke 2023년 12월 11일
Here's a MATLAB snippet that depends on the undocumented tree2str and mtree, but produces a reasonable result:
tree2str(mtree(FILENAME, '-file', '-comments'))

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by