Indent a block of code

How do you indent a block of code? For example if you enclose a block of code in an if statement, and want to indent said block.

 Accepted Answer

Wayne King
Wayne King on 29 Oct 2011

0 votes

In the MATLAB editor, you should automatically get identation of an if statement.
Other than that, highlight the text and do Text -> Small Ident, or Text -> Increase Ident

More Answers (2)

Image Analyst
Image Analyst on 30 Oct 2011

17 votes

Highlight the lines of text. Then hit tab to indent them a level to the right, and shift-tab to outdent them a level to the left.
Rachel Allen
Rachel Allen on 8 Jan 2021

5 votes

You can also use smart indent
select code then 'ctrl I'
or
select code -> right click -> Smart Indent

1 Comment

I often just type control-a (to select all) and then control-i (to properly indent the entire file).

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Asked:

on 29 Oct 2011

Commented:

on 8 Jan 2021

Community Treasure Hunt

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

Start Hunting!