Evaluating MATLAB® Commands with Notebook

Evaluating Input Commands with Notebook

After you define a MATLAB® command as an input cell, or as an autoinit cell, you can evaluate it in your M-book. Use the following steps to define and evaluate a MATLAB command:

  1. Type the command into the M-book as text. For example:

    This is a sample M-book
    
    a = magic(3)
    
  2. Position the cursor anywhere in the command. If the command is embedded in a line of text, use the mouse to select it. Then select Notebook > Define Input Cell or press Alt+D.

    Notebook defines the MATLAB command as an input cell. For example:

    This is a sample M-book
    
    [a = magic(3)]
    
  3. Specify the input cell to be evaluated by selecting it with the mouse or by placing the cursor in it. Then select Notebook > Evaluate Cell or press Ctrl+Enter.

    Notebook evaluates the input cell and displays the results in a output cell immediately following the input cell. If there is already an output cell, Notebook replaces its contents, wherever it is in the M-book. For example:

    This is a sample M-book.
    
    [a = magic(3) ]
    
    [a =
         8     1     6
         3     5     7
         4     9     2  ]
    

The text in the output cell is blue and is enclosed within cell markers. Cell markers are bold, gray brackets. They differ from the brackets used to enclose matrices by their size and weight. Error messages appear in red. For information about changing these default formats, see Modifying Styles in the M-Book Template.

Evaluating Cell Groups with Notebook

You evaluate a cell group the same way you evaluate an input cell (because a cell group is an input cell), as follows:

  1. Position the cursor anywhere in the cell or in its output cell.

  2. Select Notebook > Evaluate Cell or press Ctrl+Enter.

For information about creating a cell group, see Defining Cell Groups for Notebook.

When MATLAB evaluates a cell group, the output for all commands in the group appears in a single output cell. By default, Notebook places the output cell immediately after the cell group the first time the cell group is evaluated. If you evaluate a cell group with an existing output cell, Notebook places the results in the output cell wherever the output cell is located in the M-book.

The following illustration shows a cell group and the figure created when you evaluate the cell group.

Image of sample cell group in an M-book.

Evaluating a Range of Input Cells with Notebook

To evaluate more than one MATLAB command contained in different but contiguous input cells, follow these steps:

  1. Select the range of cells that includes the input cells you want to evaluate. You can include text that surrounds input cells in your selection.

  2. Select Notebook > Evaluate Cell or press Ctrl+Enter.

Notebook evaluates each input cell in the selection, inserting new output cells or replacing existing ones.

Evaluating a Calc Zone with Notebook

To evaluate a calc zone, follow these steps:

  1. Position the cursor anywhere in the calc zone.

  2. Select Notebook > Evaluate Calc Zone or press Alt+Enter.

For information about creating a calc zone, see Defining Calc Zones for Notebook.

By default, Notebook places the output cell immediately after the calc zone the first time the calc zone is evaluated. If you evaluate a calc zone with an existing output cell, Notebook places the results in the output cell wherever it is located in the M-book.

Evaluating an Entire M-Book

To evaluate the entire M-book, either select Notebook > Evaluate M-book or press Alt+R.

Notebook begins at the top of the M-book regardless of the cursor position and evaluates each input cell in the M-book. As it evaluates the M-book, Notebook inserts new output cells or replaces existing output cells.

Controlling Execution of Multiple Commands

When you evaluate an entire M-book, and an error occurs, evaluation continues. If you want to stop evaluation if an error occurs, follow this procedure:

  1. Select Notebook > Notebook Options.

    The Notebook Options dialog box opens.

  2. Select the Stop evaluating on error check box and click OK.

Using a Loop to Evaluate Input Cells Repeatedly with Notebook

To evaluate a sequence of MATLAB commands repeatedly, follow these steps:

  1. Use the mouse to select the input cells, including any text or output cells located between them.

  2. Select Notebook > Evaluate Loop or press Alt+L. Notebook displays the Evaluate Loop dialog box.

    Image of Evaluate Loop dialog box.

  3. Enter the number of times you want MATLAB to evaluate the selected commands in the Stop After field, then click Start. The button changes to Stop. Notebook begins evaluating the commands and indicates the number of completed iterations in the Loop Count field.

You can increase or decrease the delay at the end of each iteration by clicking Slower or Faster. Slower increases the delay. Faster decreases the delay.

To suspend evaluation of the commands, click Pause. The button changes to Resume. Click Resume to continue evaluation.

To stop processing the commands, click Stop. To close the Evaluate Loop dialog box, click Close.

Converting Output Cells to Text with Notebook

You can convert an output cell to text by undefining cells. If the output is numeric or textual, Notebook removes the cell markers and converts the cell contents to text according to the Microsoft® Word Normal style. If the output is graphical, Notebook removes the cell markers and dissociates the graphic from its input cell, but does not alter its contents.

To undefine an output cell, follow these steps:

  1. Select the output cell you want to undefine.

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

Deleting Output Cells with Notebook

To delete output cells, follow these steps:

  1. Select an output cell, using the mouse, or place the cursor in the output cell.

  2. Select Notebook > Purge Selected Output Cells or press Alt+P.

If you select a range of cells, Notebook deletes all the output cells in the selected range, but any associate input cells remain intact.

  


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