Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reformat code in MATLAB editor?

How can I reformat code in MATLAB editor? Other IDEs usually have reformat or format option that arrange position of written codes. Does editor of MATLAB have it? I use MATLAB R2013a

like image 765
Hadi Momenzadeh Avatar asked May 30 '14 18:05

Hadi Momenzadeh


People also ask

How do I make my MATLAB code readable?

Popular Answers (1) To improve readability of matlab code or any type of code it should be represented in proper way with proper spacing from left side. To do this firstly select entire code you can do it by using 'ctrl+a' then press 'ctrl+i' which will arrange your code in proper way.

How do I change the default format in MATLAB?

On the Home tab, in the Environment section, click Preferences. Select MATLAB > Command Window, and then choose a Numeric format option.


1 Answers

I have created a minimalist, configurable MATLAB source code formatter, which can be used directly in the MATLABEditor.

You can find it on GitHub: MBeautifier on GitHub

MBeautifier in action

Main features:

  • Padding operators and keywords with white spaces
  • Configurable indentation character and level. Indentation using the Smart Indent functionality of the MATLAB Editor
  • Removal/addition of continuous empty lines
  • Inserting missing element separators (commas) in matrix and cell array initializations
  • Insert missing continuous symbol line in matrix and cell array initializations
  • In-lining continuous lines
  • Formats the current page of the MATLAB Editor or only a selection in the MATLAB Editor or file(s)
  • While everything above is configurable in a single XML file

It can be used in Matlab versions starting from R2013b.

Deployment and configuration are described on GitHub (link above).

like image 180
DVarga Avatar answered Oct 17 '22 20:10

DVarga