matlabeditorcode-formatting

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


Solution

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