Defining Commands as Input Cells for Notebook
For information about evaluating the input cells you define, see Evaluating MATLAB Commands with Notebook.
To define a MATLAB command in a Word document as an input cell, follow these steps:
Type the command into the M-book as text. For example,
This is a sample M-book. a = magic(3)
Position the cursor anywhere in the command and 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. Notebook defines the MATLAB command as an input cell:
This is a sample M-book. [a = magic(3)]
Note how Notebook changes the character font of the text in the input cell to a bold, dark green color and encloses it 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 M-Book Template.
Defining Cell Groups for 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 that Notebook places immediately after the group, cell groups are useful when several MATLAB commands are needed, such as to fully define a graphic.
For example, if you define all the MATLAB commands that produce a graphic as a cell group and then evaluate that cell group, Notebook 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 with Notebook for information about evaluating a cell group. For information about ungrouping a cell group, see Ungroup Cells.
To create a cell group, follow these steps:
- Use the mouse to select the input cells that are to make up the group.
- Select Notebook > Group Cells or press Alt+G.
Notebook converts the selected cells into a cell group and replaces cell markers with a single pair that surrounds the group:
This is a sample cell group. [date a = magic(3) ][tip]Note the following:[/tip]
- A cell group cannot contain output cells. If the selection includes output cells, Notebook deletes them.
- A cell group cannot contain text. If the selection includes text, Notebook places the text after the cell group. However, if the text precedes the first input cell in the selection, Notebook leaves it where it is.
- If you select part or all of an output cell, but not its input cell, Notebook includes the input cell in the cell group.
When you create a cell group, Notebook defines it as an input cell unless its first line is an autoinit cell, in which case Notebook defines the group as an autoinit cell.
Defining Autoinit Input Cells for Notebook
You can use autoinit cells to specify MATLAB commands to be automatically evaluated each time an M-book is opened. This is a quick and easy way to initialize the workspace. Autoinit cells are input cells with the following additional characteristics:
- Notebook evaluates the autoinit cells when it opens the M-book.
- Notebook displays the commands in autoinit cells using dark blue characters.
Autoinit cells are otherwise identical to input cells.
You can create an autoinit cell in one of the following two ways:
- Enter the MATLAB command as text, then convert the command to an autoinit cell by selecting Notebook > Define AutoInit Cell.
- If you already entered the MATLAB command as an input cell, you can convert the input cell to an autoinit cell. Either select the input cell or position the cursor in the cell, then select Notebook > Define AutoInit Cell.
See Evaluating MATLAB Commands with Notebook for information about evaluating autoinit cells.
Defining Calc Zones for Notebook
You can partition an M-book into self-contained sections, called calc zones. A calc zone is a contiguous block of text, input cells, and output cells. Notebook inserts Microsoft Word section breaks before and after the section to define 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. An M-book can contain any number of calc zones.[help]Using calc zones does not affect the scope of the variables in an M-book. Variables used in one calc zone are accessible to all calc zones.[/help]
After you create the text and cells that you want to include in the calc zone, define the calc zone by following these steps:
- Select the input cells and text to be included in the calc zone.
- Select Notebook > Define Calc Zone.
See Evaluating a Calc Zone with Notebook for information about evaluating a calc zone.
Converting an Input Cell to Text with Notebook
To convert an input cell (or an autoinit cell or a cell group) to text, follow these steps:
- Select the input cell with the mouse or position the cursor in the input cell.
- Select Notebook > Undefine Cells or press Alt+U.
When Notebook converts the cell to text, it reformats the cell contents according to the Microsoft Word Normal style. For more information about M-book styles, see Modifying Styles in the M-Book Template. When you convert an input cell to text, Notebook also converts the corresponding output cell to text.