Skip to Main Content Skip to Search
Product Documentation

About MATLAB Notebooks

Contents of MATLAB Notebooks

Using the notebook command, you can create a Microsoft Word document, that contains text, MATLAB commands, and the output from MATLAB commands.

You can think of this document as a record of an interactive MATLAB session annotated with text, or as a document embedded with live MATLAB commands and output. This documentation refers to this Microsoft Word document as a MATLAB Notebook.

Creating or Opening a MATLAB Notebook

This section includes information on performing the following tasks:

Issuing the notebook Command from the MATLAB Desktop

If you are running notebook for the first time since you installed a new version of MATLAB, follow the instructions in Configuring the MATLAB notebook Software.

Then, to create a MATLAB Notebook from within MATLAB desktop, type the following in the Command Window:

notebook

The notebook command starts Word on your system and creates a MATLAB Notebook, called Document1.

When Word is opening, if a dialog box appears asking you to enable or disable macros, choose to enable macros. The notebook command defines Microsoft Word macros that enable MATLAB to interpret the different types of cells that hold MATLAB commands and their output. For more information on macro security, see Configuring the MATLAB notebook Software.

Depending on the version of Word you are using, one of the following occurs:

Creating a MATLAB Notebook

After issuing the notebook command, you can create a MATLAB Notebook as follows:

Microsoft product screen shot reprinted with permission from Microsoft Corporation.

Opening an Existing MATLAB Notebook

You can use the notebook command to open an existing MATLAB Notebook, as shown in the following code, where filename is the notebook you want to open.

notebook filename

Alternatively, you can double-click a notebook file in a Windows file management tool, such as Explorer.

When you double-click a notebook, Microsoft Word opens it and starts MATLAB if it is not already running.

Converting a Word Document to a MATLAB Notebook

To convert a Word document to a MATLAB Notebook, insert it into a notebook file, as described in the steps that follow. Choose the set of steps that corresponds to the version of Word you are using:

Microsoft Word 2002, or 2003.  

  1. Create a MATLAB Notebook.

    For details, see Creating or Opening a MATLAB Notebook.

  2. From the Insert menu, select File.

  3. Select the file you want to convert.

  4. Click OK.

Microsoft Word 2007 and Later Releases.  

  1. Create a MATLAB Notebook.

    For details, see Creating or Opening a MATLAB Notebook.

  2. From the Insert tab, in the Text group, click the arrow next to Object.

  3. Select Text from File, as shown in the image that follows.

    The Insert File dialog box opens.

  4. In the Insert File dialog box, select the file that you want to convert, and then click OK.

Image of Microsoft Word 2007 with Insert tab > Text > Object open.

Microsoft product screen shot reprinted with permission from Microsoft Corporation.

Entering Commands in a MATLAB Notebook

You enter MATLAB commands in a notebook the same way you enter text in any other Word document. For example, you can enter the following text in a Word document. The example uses text in Courier Font but you can use any font:

Here is a sample MATLAB Notebook.

a = magic(3)

To execute the MATLAB magic command in this document, follow the steps described in these sections:

MATLAB displays the output of the command in the Word document in an output cell.

Protecting the Integrity of Your Workspace in MATLAB Notebooks

When you work on more than one MATLAB Notebook in a single word-processing session, note that:

If you use the same variable names in more than one notebook, data used in one notebook can be affected by another notebook. You can protect the integrity of your workspace by specifying the clear command as the first autoinit cell in the notebook.

Ensuring Data Consistency in MATLAB Notebooks

You can think of a MATLAB Notebook as a sequential record of a MATLAB session. When executed in order, from the first MATLAB command to the last, the notebook accurately reflects the relationships among these commands.

If, however, you change an input cell or output cell as you refine your notebook, it can contain inconsistent data. Input cells that depend on either the contents or the results of the changed cells do not automatically recalculate when you make a change.

When working on a notebook, consider selecting Evaluate MATLAB Notebook periodically to ensure that your notebook data is consistent. You can also use calc zones to isolate related commands in a section of the notebook, and then use Evaluate Calc Zone to execute only those input cells contained in the calc zone.

Debugging and MATLAB Notebooks

Do not use debugging functions or the Editor while evaluating cells within a MATLAB Notebook. Instead:

  1. Complete debugging files from within MATLAB.

  2. Clear all the breakpoints.

  3. Access the file using notebook.

If you debug while evaluating a notebook, you can experience problems with MATLAB.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

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