MATLAB Notebook for Word



MATLAB Notebook for Microsoft Word

The MATLAB Notebook or M-book is an interface for accessing MATLAB in a seamless manner through the word processing environment of Microsoft Word. The Notebook interface allows commands created within a Word document to be sent to MATLAB for evaluation. The result of MATLAB's processing of the command is returned to Word and inserted in the document. Both text and graphical output from MATLAB are supported.

Setting Up Notebook

The first time you wish to use the MATLAB Notebook (M-book) feature on a new computer, you need to configure it. Do the following:

1. Close any MATLAB M-books that may be open in Microsoft Word.

2. Start MATLAB and at the MATLAB command prompt type

notebook –setup

3. You will be prompted to choose your version of Microsoft Word – press 2 for Miscrosoft Word 2000.

4. You may then be prompted for the location of the file normal.dot. Use the browser to search for this file. It should be located on your U: drive.

The Notebook feature is now ready to use. You will need to follow this procedure each time you log onto a different computer.

Creating/Opening a Notebook

Creating/opening a Notebook starts Microsoft Word on your system. The best approach for opening an M-book is as follows:

• To open an existing M-book, click on the existing Microsoft Word document that is a M-book. It automatically opens in Microsoft Word.

• To create a new M-book from within Microsoft Word, open an existing M-book and from the File menu select New M-book.

You can also create/open a Notebook from within MATLAB. However, this approach may or may not work, depending on the way MATLAB was configured on your computer.

• To open an existing M-book from within MATLAB, at the MATLAB command prompt type

notebook filename.doc

where filename.doc is the name of the Microsoft Word document which is the M-book. Make sure the MATLAB working directory is set to be the directory where the M-book is located.

• To create a new M-book from within MATLAB, at the MATLAB command prompt type

notebook

Important notes when Word is opening:

• If a dialog box appears asking you to enable or disable macros, choose to enable macros.

• If a dialog box appears asking you enter the path for MATLAB, click okay to choose the default path (which should be c:\matlab\bin).

A MATLAB Notebook (or M-book) automatically defines Microsoft Word macros that enable MATLAB to interpret the different types of cells that hold MATLAB commands and their output. Notebook adds the Notebook menu to the Word menu bar. Use this menu, to access and work with Notebook features. Some of these features are now described.

Working with M-books

Within your M-book MS-Word document, you can type and format text as you would in a normal Word document. You can also type in and execute MATLAB commands and the output will be placed directly in your document. A MATLAB command must be defined as an input cell.

Defining MATLAB Commands as Input Cells

1. Type your MATLAB command on a new line and then position the cursor anywhere in the command, or ff the command is embedded in a line of text, use the mouse to select it.

2. Select Notebook -> Define Input Cell or press Alt+D.

Notebook defines the MATLAB command as an input cell. 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.

A special type of input cell, called an autoinit cell causes Notebook to evaluate the autoinit cells when the M-book is opened, and these are displayed using dark blue characters. This is a good way to initialize/clear your workspace. They are defined by selecting the MATLAB command with the mouse and then selecting Notebook->Define AutoInit Cell

Defining Input Cell Groups

You can collect several input cells into a single input cell, called a cell group. 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. To create a cell group:

1. Use the mouse to select the input cells that are to make up the group.

2. 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. A cell. group cannot contain output cells, nor text

Evaluating Input Cells or Input Cell Groups

1. Selecting an input cell with the mouse or placing the cursor in it.

2. 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. More than one input cell or input cell group can be evaluated by using the mouse to select the range of cells (including any text) and then pressing Ctrl+Enter.

Defining and Evaluating Calc Zones

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. Calc zones are just a convenient way of partitioning your M-book into sections that can be evaluated together. To create a calc zone:

1. Select the input cells, output cells and text to be included in the calc zone.

2. Select Notebook -> Define Calc Zone.

To evaluate a calc zone:

1. Position the cursor anywhere in the calc zone.

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

Evaluating an Entire M-book

To evaluate the entire M-book:

1. 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. 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.

*** IMPORTANT – Ensuring Data Consistency

An M-book can be thought of as a sequential record of a MATLAB session. When executed in order, from the first MATLAB command to the last, the M-book accurately reflects the relationships among these commands. If, however, you change an input cell or output cell as you refine your M-book, Notebook does not automatically recalculate input cells that depend on either the contents or the results of the changed cells. As a result, the M-book may contain inconsistent data. When working on an M-book, you might find it useful to select Evaluate M-book periodically to ensure that your M-book data is consistent. You could also use calc zones to isolate related commands in a section of the M-book. You can then use Evaluate Calc Zone to execute only those input cells contained in the calc zone. Protecting the Integrity of Your Workspace

Additional M-book Features

Converting Output Cells to Text

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:

1. Select the output cell you want to undefine.

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

Deleting Output Cells

To delete output cells:

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. For example, to delete all the output cells, from the Edit Menu you could Select All and the use the Notebook Menu to Purge Selected Output Cells.

Controlling Graphic Output

By default, graphic output is embedded in an M-book. To display graphic output in a separate figure window:

1. Select Notebook -> Notebook Options.

2. In the Notebook Options dialog box, remove the check from the Embed Figures in M-book check box.

3. Click OK.

Converting a Word Document to an M-book

1. Create a new M-book.

2. From the Insert menu, select the File.

3. Select the file you want to convert.

4. Click OK.

Setting Up MATLAB Help for More Information on M-books

All of this information and much more can be found in the MATLAB Help Files. From the MATLAB Help Menu, select MATLAB Help. If an error comes up saying that the help files can't be found, do the following in MATLAB:

1. Select File->Preferences.

2. Select Help from the left hand menu.

3. Near the top of the right hand menu, click on the icon with the 3 dots (…) to browse the Local or Network Directory for the documentation location.

4. Select the folder H:\help

5. Click OK

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download