Skip to Main Content Skip to Search
Product Documentation

Defining MATLAB Commands as Input Cells for a MATLAB Notebook

For information about evaluating the input cells you define, see Evaluating MATLAB Commands in a MATLAB Notebook.

Defining Input Cells for a MATLAB Notebook

To define a MATLAB command in a Word document as an input cell, follow these steps:

  1. Type the command into the MATLAB Notebook as text. For example,

    This is a sample MATLAB Notebook.
    
    a = magic(3)
    
  2. Position the cursor anywhere in the command, and then select Notebook > Define Input Cell or press Alt+D. If the command is embedded in a line of text, use the mouse to select it. This defines the MATLAB command as an input cell:

    This is a sample MATLAB Notebook.
    
    [a = magic(3)]
    

Note how the character font of the text in the input cell changes to a bold, dark green color and appears within cell markers. Cell markers are bold, gray brackets. They differ from the brackets used to enclose matrices by their size and weight. For information about changing these default formats, see Modifying Styles in the MATLAB Notebook Template.

Defining Cell Groups for a MATLAB Notebook

You can collect several input cells into a single input cell. This is called a cell group. Because all the output from a cell group appears in a single output cell immediately after the group, cell groups are useful when you need several MATLAB commands. For instance, to define a graphic fully.

If you define all the MATLAB commands that produce a graphic as a cell group, and then evaluate that cell group, it generates a single graphic that includes all the graphic components defined in the commands. If instead you define all the MATLAB commands that generate the graphic as separate input cells, evaluating the cells generates multiple graphic output cells.

See Evaluating Cell Groups for information about evaluating a cell group. For information about ungrouping a cell group, see Ungroup Cells.

Creating a Cell Group

To create a cell group:

  1. Use the mouse to select the input cells that are to make up the group.

  2. Select Notebook > Group Cells or press Alt+G.

The selected cells convert into a cell group and cell markers convert to a single pair that surrounds the group:

This is a sample cell group.

[date 
a = magic(3) ]

Note the following:

When you create a cell group, it is an input cell, unless its first line is an autoinit cell. In that case, the group is an autoinit cell.

Defining Autoinit Input Cells for a MATLAB Notebook

You can use autoinit cells to specify MATLAB commands be evaluated automatically each time a MATLAB Notebook opens. This is a quick and easy way to initialize the workspace. Autoinit cells are input cells with the following additional characteristics:

Autoinit cells are otherwise identical to input cells.

Creating an Autoinit Cell for a MATLAB Notebook

You can create an autoinit cell in one of the following two ways:

See Evaluating MATLAB Commands in a MATLAB Notebook for information about evaluating autoinit cells.

Defining Calc Zones for a MATLAB Notebook

You can partition a MATLAB Notebook into self-contained sections, called calc zones. A calc zone is a contiguous block of text, input cells, and output cells. Section breaks appear before and after the section, defining the calc zone. The section break indicators include bold, gray brackets to distinguish them from standard Word section breaks.

You can use calc zones to prepare problem sets, making each problem a separate calc zone that can be created and tested on its own. A notebook can contain any number of calc zones.

Creating a Calc Zone

After you create the text and cells that you want to include in the calc zone, define the calc zone by following these steps:

  1. Select the input cells and text you want to include in the calc zone.

  2. Select Notebook > Define Calc Zone.

See Evaluating a Calc Zone for information about evaluating a calc zone.

Converting an Input Cell to Text in a MATLAB Notebook

To convert an input cell (or an autoinit cell or a cell group) to text, follow these steps:

  1. Select the input cell with the mouse or position the cursor in the input cell.

  2. Select Notebook > Undefine Cells or press Alt+U.

When the cell converts to text, the cell contents reformat according to the Microsoft Word Normal style. For more information about MATLAB Notebook styles, see Modifying Styles in the MATLAB Notebook Template. When you convert an input cell to text, the corresponding output cell also converts to text.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS