How can I reformat code in MATLAB editor?

后端 未结 2 1439
粉色の甜心
粉色の甜心 2020-12-05 08:31

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 MATL

相关标签:
2条回答
  • 2020-12-05 09:07

    A few default formatting shortcuts for the Matlab editor - assuming windows

    ctrl+A - Select all
    ctrl+I - Smart Indend
    ctrl+= - Collapse All (loop control statements)
    ctrl+shift+= Expand All (loop control statements)
    ctrl+] - Increase indent
    ctrl+[ - Decrease indent
    ctrl+J - Wrap comments


    Other useful keyboard shortcuts for Matlab editor

    ctrl+R - Comment out selection (adds leading % to all selected lines)
    ctrl+T - Uncomment selection (removes leading % from selected lines)
    ctrl+K - Kill line (deletes from caret to end of line, if line is empty deletes newline)
    ctrl+M - View or expand current message
    ctrl+F1 - Display function hints


    Additional shortcuts can be found or defined in Prefrences>Keyboard>Shortcuts

    Finally a special mention to ... for line continuation...
    example:

    [output1,output2,output3]=calltoafunctionwithlotsofinputs(...
        intput1, input2, input3, input4, input5, ...
        'property1', propertyvalue1, ...
        'property2', propertyvalue2)
    
    0 讨论(0)
  • 2020-12-05 09:07

    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

    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).

    0 讨论(0)
提交回复
热议问题