Using MATLAB (779505), страница 37
Текст из файла (страница 37)
An M-book cancontain any number of calc zones.10-10Defining MATLAB Commands as Input CellsNote 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.Creating a Calc ZoneAfter you create the text and cells you want to include in the calc zone, youdefine the calc zone by following these steps:1 Select the input cells and text to be included in the calc zone.2 Choose the Define Calc Zone command from the Notebook menu.Note You must select an input cell and its output cell in their entirety toinclude them in the calc zone.See “Evaluating a Calc Zone” on page 10-14 for information about evaluating acalc zone.Converting an Input Cell to TextTo convert an input cell (or an autoinit cell or a cell group) to text:1 Select the input cell with the mouse or position the cursor in the input cell.2 Select the Undefine Cells command from the Notebook menu or pressAlt+U.When Notebook converts the cell to text, it reformats the cell contentsaccording to the Microsoft Word Normal style.
For more information aboutM-book styles, see “Modifying Styles in the M-Book Template” on page 10-18.When you convert an input cell to text, Notebook also converts thecorresponding output cell to text.10-1110Using NotebookEvaluating MATLAB CommandsAfter 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 andevaluate a MATLAB command:1 Type the command into the M-book as text. For example,This is a sample M-booka = magic(3)2 Position the cursor anywhere in the command and choose the Define InputCell command from the Notebook menu or press Alt+D.
If the command isembedded in a line of text, use the mouse to select it. Notebook defines theMATLAB command as an input cell. For example,This is a sample M-book[a = magic(3)]3 Choose the Evaluate Cell command from the Notebook menu or pressCtrl+Enter. You can specify the input cell to be evaluated by selecting itwith the mouse, or placing the cursor in it.Notebook evaluates the input cell and displays the results in a output cellimmediately 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 =834159672]The text in the output cell is blue and is enclosed within cell markers. Cellmarkers are bold, gray brackets. They differ from the brackets used to enclosematrices by their size and weight. Error messages appear in red. For10-12Evaluating MATLAB Commandsinformation about changing these default formats, see “Modifying Styles in theM-Book Template” on page 10-18.For more information about evaluating MATLAB commands in an M-book, see:• “Evaluating Cell Groups” on page 10-13• “Evaluating a Range of Input Cells” on page 10-14• “Evaluating a Calc Zone” on page 10-14• “Evaluating an Entire M-Book” on page 10-15• “Using a Loop to Evaluate Input Cells Repeatedly” on page 10-15.• “Converting Output Cells to Text” on page 10-16• “Deleting Output Cells” on page 10-17Evaluating Cell GroupsYou evaluate a cell group the same way you evaluate an input cell (because acell group is an input cell):1 Position the cursor anywhere in the cell or in its output cell.2 Choose the Evaluate Cell command from the Notebook menu or pressCtrl+Enter.For information about creating a cell group, see “Defining Cell Groups” onpage 10-8.When MATLAB evaluates a cell group, the output for all commands in thegroup appears in a single output cell.
By default, Notebook places the outputcell 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 theresults in the output cell wherever it is located in the M-book.Note Text or numeric output always comes first, regardless of the order ofthe commands in the group.The illustration shows a cell group and the figure created when you evaluatethe cell group.10-1310Using NotebookEvaluating a Range of Input CellsTo evaluate more than one MATLAB command contained in different butcontiguous input cells: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 Choose the Evaluate Cell command from the Notebook menu or pressCtrl+Enter.Notebook evaluates each input cell in the selection, inserting new output cellsor replacing existing ones.Evaluating a Calc ZoneTo evaluate a calc zone:1 Position the cursor anywhere in the calc zone.10-14Evaluating MATLAB Commands2 Select the Evaluate Calc Zone command from the Notebook menu or pressAlt+Enter.For information about creating a calc zone, see “Defining Calc Zones” onpage 10-10.By default, Notebook places the output cell immediately after the calc zone thefirst time the calc zone is evaluated.
If you evaluate a calc zone with an existingoutput cell, Notebook places the results in the output cell wherever it is locatedin the M-book.Evaluating an Entire M-BookTo evaluate the entire M-book, either select the Evaluate M-book command orpress Alt+R.Notebook begins at the top of the M-book regardless of the cursor position andevaluates each input cell in the M-book.
As it evaluates the M-book, Notebookinserts new output cells or replaces existing output cells.Controlling Execution of Multiple CommandsWhen you evaluate an entire M-book, and an error occurs, evaluationcontinues. If you want to stop evaluation if an error occurs, follow thisprocedure:1 Choose Notebook Options from the Notebook menu.2 Click the Stop evaluating on error check box.Using a Loop to Evaluate Input Cells RepeatedlyTo evaluate a sequence of MATLAB commands repeatedly:1 Use the mouse to select the input cells, including any text or output cellslocated between them.2 Choose the Evaluate Loop command or press Alt+L.
Notebook displays theEvaluate Loop dialog box.10-1510Using Notebook3 Enter the number of times you want MATLAB to evaluate the selectedcommands in the Stop After field, then click on the Start button. The labelon the button changes to Stop. Notebook begins evaluating the commandsand 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 clickingon the Slower or Faster button. Slower increases the delay. Faster decreasesthe delay.To suspend evaluation of the commands, click on the Pause button. The labelon the button changes to Resume.
Click on the Resume button to continueevaluation.To stop processing the commands, click on the Stop button. To close theEvaluate Loop dialog box, click on the Close button.Converting Output Cells to TextYou can convert an output cell to text using the Undefine Cells command. Ifthe output is numeric or textual, Notebook removes the cell markers andconverts the cell contents to text according to the Microsoft Word Normal style.If the output is graphical, Notebook removes the cell markers and dissociatesthe graphic from its input cell, but does not alter its contents.Note Undefining an output cell does not affect the associated input cell.To undefine an output cell:1 Select the output cell you want to undefine.10-16Evaluating MATLAB Commands2 Choose the Undefine Cells command from the Notebook menu or pressAlt+U.Deleting Output CellsTo delete output cells:1 Select an output cell, using the mouse, or place the cursor in the output cell.2 Choose the Purge Output Cells command from the Notebook menu or pressAlt+P.If you select a range of input cells, each with output cells, Notebook deletes allthe associated output cells.10-1710Using NotebookPrinting and Formatting an M-BookThis section describes:• “Printing an M-Book” on page 10-18• “Modifying Styles in the M-Book Template” on page 10-18• “Choosing Loose or Compact Format” on page 10-19• “Controlling Numeric Output Format” on page 10-20• “Controlling Graphic Output” on page 10-20Printing an M-BookYou can print all or part of an M-book by selecting the Print command from theFile menu.
Word follows these rules when printing M-book cells and graphics:• Cell markers are not printed.• Input cells, autoinit cells, and output cells (including error messages) areprinted according to their defined styles. If you prefer to print these cellsusing black type instead of colors or shades of gray, you can modify the styles.Modifying Styles in the M-Book TemplateYou can control the appearance of the text in your M-book by modifying thepredefined styles stored in the M-book template. These styles control theappearance of text and cells. By default, M-books use the Word Normal stylefor all other text.For example, if you print an M-book on a color printer, input cells appear darkgreen, output and autoinit cells appear dark blue, and error messages appearred.















