Desktop Tools and Development Environment Previous page   Next Page

Navigating and Evaluating with Cells

While you develop an M-file, you can use these Editor/Debugger cell features:

Navigating Among Cells in an M-File

To move to the next cell, select Cell -> Next Cell. To move to the previous cell, select Cell -> Previous Cell. To move to a specific cell, click the Show Cell Titles button and from it, select the cell title to which you want to move. You can also go to cells by selecting Edit -> Go To.

Evaluating Cells in an M-File

To evaluate the code in a cell, use the Cell menu evaluation items or buttons in the cell toolbar. When you evaluate a cell, the results display in the Command Window, figure window, or otherwise, depending on the code evaluated.

The cell evaluation features run the code currently shown in the Editor/Debugger, even if the file contains unsaved changes. The file does not have to be on the search path. To evaluate a cell, it must contain all the values it requires, or the values must already exist in the MATLAB workspace.

Evaluate Current Cell.   Select Cell -> Evaluate Current Cell or click the Evaluate Cell button to run the code in the current cell.

Evaluate and Advance.   Select Cell -> Evaluate Current Cell and Advance or click the Evaluate Cell and Advance button to run the code in the current cell and move to the next cell.

Evaluate File.   Select Cell -> Evaluate Entire File or click the Evaluate Entire File button to run all of the code in the file.

Modifying Values in a Cell

You can use cell features to modify numbers in a cell, which also automatically reevaluates the cell.

To modify a number in a cell, select the number (or place the cursor near it) and use the value modification tool in the cell toolbar. Using this tool, you can specify a number and press the appropriate math operator to add (increment), subtract (decrement), multiply, or divide the number. The cell then automatically reevaluates.

Image of increment/decrment and divisor/multiplier buttons and numbers on cell toolbar.

You can use the numeric keypad operator keys (-, +, /, and *) instead of the operator buttons on the toolbar.

Example--Evaluate Cells

In this example, modify the values for x in sine_wave.m:

  1. Run the first cell in sine_wav.m. Click somewhere in the first cell, that is, between lines 1 and 6. Select Cell -> Evaluate Current Cell. The following figure appears.

    Image of plot showing the results of running sine_wave.m. The plot is not smooth.

  2. Assume you want to produce a smoother curve. Use more values for x in 0:1:6*pi. Position the cursor in line 4, next to the 1. In the cell toolbar, change the 1.1 default multiply/divide by value to 2. Click the Divide button Button with tooltip .
  1. Line 4 becomes

    Image of line 4, showing x = 0:0.5:6*pi.

    and the length of x doubles. The plot automatically updates. The curve still has some rough edges.

  1. To add more values for x, click the divide button three more times. Line 4 becomes

    Image of line 4, showing x = 0:0625.5:6*pi.

  1. The curve is smooth, but because there are more values, processing time is slower. It would be better to find a smaller x that still produces a smooth curve.

  1. In the cell toolbar, click the multiply button once. The increment for x as shown in line 4 changes from 0.0625 to 0.125.
  1. The resulting curve is still smooth.

  1. Save these changes. Select File -> Save.
  2. You do not need to evaluate the entire file to modify the plot properties. Instead, evaluate the second cell, that is, lines 7 through 12. You can use the shortcut Ctrl+Enter to evaluate the current cell. (The shortcut appears with the menu item, Cell -> Evaluate Current Cell).
  1. MATLAB updates the figure.

    Image of plot of sine_wave.m, showing a smoother curve.


Previous page  Defining Cells Using Cells in Function M-Files Next page

© 1994-2005 The MathWorks, Inc.