Desktop Tools and Development Environment |
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.
You can use the numeric keypad operator keys (-, +, /, and *) instead of the operator buttons on the toolbar.
Note MATLAB does not automatically save changes you make to values using the cell toolbar. To save changes, select File -> Save. |
Example--Evaluate Cells
In this example, modify the values for x
in sine_wave.m
:
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.
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 .
and the length of x
doubles. The plot automatically updates. The curve still has some rough edges.
x
that still produces a smooth curve.
x
as shown in line 4 changes from 0.0625
to 0.125
.
Defining Cells | Using Cells in Function M-Files |
© 1994-2005 The MathWorks, Inc.