MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Improve Code Readability


In this section...
“Indenting Code” on page 24-20
“Right-Side Text Limit Indicator” on page 24-22
“Code Folding — Expand and Collapse Code Constructs” on page 24-22
“Code Refactoring — Automatically convert selected code to a function” on page 24-26

Indenting Code


Indenting code makes reading statements such as while loops easier. To set and apply
indenting preferences to code in the Editor:

1
On the Home tab, in the Environment section, click Preferences.

The Preferences dialog box opens.
2 Select MATLAB > Editor/Debugger > Language.

(^3) Choose a computer language from the Language drop-down list.
(^4) In the Indenting section, select or clear Apply smart indenting while typing,
depending on whether you want indenting applied automatically, as you type. Smart
indenting is always applied automatically in the Live Editor.
If you clear this option, you can manually apply indenting by selecting the lines in the
Editor to indent, right-clicking, and then selecting Smart Indent from the context
menu.
(^5) Do one of the following:



  • If you chose any language other than MATLAB in step 2, click OK.

  • If you chose MATLAB in step 2, select a Function indenting format, and then
    click OK. Function indent formats are:

    • Classic — The Editor aligns the function code with the function declaration.

    • Indent nested functions — The Editor indents the function code within a
      nested function.

    • Indent all functions — The Editor indents the function code for both
      main and nested functions.




24 Coding and Productivity Tips

Free download pdf