MATLAB® 7 Desktop Tools and Development Environment
How to Contact The MathWorks Web Newsgroup www.mathworks.com/contact_TS.html Technical Support www.mathworks.com comp.soft-sys.matlab suggest@mathworks.com bugs@mathworks.com doc@mathworks.com service@mathworks.com info@mathworks.com Product enhancement suggestions Bug reports Documentation error reports Order status, license renewals, passcodes Sales, pricing, and general information 508-647-7000 (Phone) 508-647-7001 (Fax) The MathWorks, Inc.
Revision History June 2004 First printing October 2004 March 2005 March 2005 June 2005 September 2005 March 2006 September 2006 March 2007 September 2007 Online only Online only Second printing Third printing Online only Online only Online only Online only Online only New for MATLAB 7.0 (Release 14). Formerly part of Using MATLAB. Revised for MATLAB 7.0.1 (Release 14SP1) Revised for MATLAB 7.0.4 (Release 14SP2) Revised for MATLAB 7.0.4 (Release 14SP2) Minor revision for MATLAB 7.0.
Contents Startup and Shutdown 1 Starting MATLAB on Windows Platforms . . . . . . . . . . . . Starting MATLAB from the Windows Desktop or a DOS Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Starting MATLAB from an M-File or Other File Type in Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Utility to Change Windows File Associations . . . . . . . . . . . Changing File Associations for MATLAB from Windows . . 1-2 ...............
Other Startup Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Error Log Reporter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Passing Perl Variables on Startup . . . . . . . . . . . . . . . . . . . . Startup and Calling Java from MATLAB . . . . . . . . . . . . . . 1-21 1-21 1-21 1-22 Quitting MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ways to Quit MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Confirm Quitting MATLAB .
Examples of Useful Shortcuts . . . . . . . . . . . . . . . . . . . . . . . Creating Shortcuts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Running Shortcuts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Shortcuts Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Organizing and Editing Shortcuts . . . . . . . . . . . . . . . . . . . . 2-32 2-33 2-35 2-35 2-38 Keyboard Shortcuts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Syntax Highlighting Colors . . . . . . . . . . . . . . . . . . . . . . . . . Other Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . See Also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-73 2-75 2-75 General Preferences for MATLAB . . . . . . . . . . . . . . . . . . . Setting General Preferences for MATLAB . . . . . . . . . . . . . Default Behavior of the Delete Function . . . . . . . . . . . . . . . MAT-Files Preferences . . . . . . .
Cut, Copy, Paste, and Undo Features . . . . . . . . . . . . . . . . . . Enter Multiple Lines Without Running Them . . . . . . . . . . Entering Multiple Functions in a Line . . . . . . . . . . . . . . . . Entering Long Statements (Line Continuation) . . . . . . . . . Recalling Previous Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . Tab Completion in the Command Window . . . . . . . . . . . . . Keyboard Shortcuts in the Command Window . . . . . . . . . . Navigating Above the Command Line . . . .
Help for Using MATLAB 4 x Contents Help Browser Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . About the Help Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . Opening the Help Browser . . . . . . . . . . . . . . . . . . . . . . . . . . Resizing the Help Browser . . . . . . . . . . . . . . . . . . . . . . . . . . Types of Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . Accessing Documentation on the Web . . . . . . . . . . . . . . . . .
Help Fonts and Colors Preferences . . . . . . . . . . . . . . . . . . . 4-39 Printed Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . About Printed Manuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Printing a Page from the Help Browser . . . . . . . . . . . . . . . . Printing the PDF Version of Documentation . . . . . . . . . . . . 4-42 4-42 4-42 4-42 Help Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About Help Functions . . . . .
Creating Plots from the Workspace Browser . . . . . . . . . . . . Opening Variables and Objects for Viewing and Editing . . Preferences for the Workspace Browser . . . . . . . . . . . . . . . Viewing and Editing Workspace Variables with the Array Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About the Array Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Opening the Array Editor . . . . . . . . . . . . . . . . . . . . . . . . . . .
Accessing Source Control Features . . . . . . . . . . . . . . . . . . . Preferences for the Current Directory Browser . . . . . . . . . 5-54 5-54 Editing and Debugging M-Files 6 Begin with Existing Code . . . . . . . . . . . . . . . . . . . . . . . . . . . Create M-Files from Command Window and History . . . . . Use Existing M-Files and Examples . . . . . . . . . . . . . . . . . . 6-3 6-3 6-3 Ways to Edit, Evaluate, and Debug M-Files . . . . . . . . . . .
Code Folding—Expanding and Collapsing M-File Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Split Screen Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Navigating in an M-File . . . . . . . . . . . . . . . . . . . . . . . . . . . . Going to a Line Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . Going to a Function (Subfunctions and Nested Functions) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using Configurations — Running M-Files with Input Arguments in the Editor/Debugger . . . . . . . . . . . . . . . . . Create and Run a Configuration for an M-file . . . . . . . . . . Create and Run Multiple Configurations for an M-File . . . Find Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Remove Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Reassociate and Rename Configurations . . . . . . . . . . . . . . .
Tuning and Managing M-Files 7 Directory Reports in Current Directory Browser . . . . . Accessing and Using Directory Reports . . . . . . . . . . . . . . . . TODO/FIXME Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Help Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Contents Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Dependency Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Coverage Report . . .
Text Markup for Indented Text, Lists, and Graphics . . . . . Text Markup for HTML, LaTeX, and TeX Equation Output Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Text Markup for Bold, Italic, and Monospaced Text Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Text Markup for Inline Links . . . . . . . . . . . . . . . . . . . . . . . . 8-14 Publishing M-Files Using Cells . . . . . . . . . . . . . . . . . . . . . .
Modifying Styles in the M-Book Template . . . . . . . . . . . . . Choosing Loose or Compact Format for Notebook . . . . . . . Controlling Numeric Output Format for Notebook . . . . . . . Controlling Graphic Output for Notebook . . . . . . . . . . . . . . 8-47 8-48 8-49 8-49 ............................. 8-53 Notebook Feature Reference . . . . . . . . . . . . . . . . . . . . . . . . Bring MATLAB to Front . . . . . . . . . . . . . . . . . . . . . . . . . . . . Define Autoinit Cell . . . . . . . . . . . .
Undoing the Checkout ............................. Additional Source Control Actions on Windows . . . . . . Getting the Latest Version of Files for Viewing or Compiling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Removing Files from the Source Control System . . . . . . . . Showing File History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Comparing the Working Copy of a File to the Latest Version in Source Control . . . . . . . . . . . . . . . . . . . . . . . .
Checking Files Out of the Source Control System on UNIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Checking Out One or More Files Using the Current Directory Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Checking Out a Single File Using the Editor/Debugger, Simulink, or Stateflow . . . . . . . . . . . . . . . . . . . . . . . . . . . Function Alternative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1 Startup and Shutdown This set of topics includes options for customizing the startup and shutdown. Starting MATLAB on Windows Platforms (p. 1-2) Ways to start MATLAB®, including from a desktop icon, or from a file in Windows Explorer. Associating file types with MATLAB. Starting MATLAB on UNIX Platforms (p. 1-6) MATLAB startup on UNIX. Starting MATLAB on Macintosh Platforms (p. 1-7) Ways to start MATLAB on a Macintosh, including from a MATLAB file type in the Finder. Startup Directory for MATLAB (p.
1 Startup and Shutdown Starting MATLAB on Windows Platforms In this section...
Starting MATLAB on Windows Platforms associate with MATLAB. For example, if you accepted the default options, double-clicking an M-file in Windows Explorer opens the file in the MATLAB Editor/Debugger. Other default options associate MEX-files and P-files with MATLAB in Windows Explorer, which assigns the file types a MATLAB icon. However, double-clicking a file with a .mex (.mexw32 or .mexw64), or .p extension does not run or open the file in MATLAB.
1 Startup and Shutdown After associating a file type with MATLAB, you can open other applications using that file type via the context menu. For example, right-click myfile.mat, and from the context menu, select Open With. Microsoft Access will be one of the options. File associations for Windows Explorer do not affect what happens when you open one of these file types from within MATLAB.
Starting MATLAB on Windows Platforms using the MATLAB tool associated with that file type. For example, even if you associate .mat files with Microsoft Access, when you open a MAT-file from within MATLAB, it opens the Import Wizard to load the data. Utility to Change Windows File Associations If you are viewing this topic in the MATLAB Help browser, you can run one of the utilities provided here to create Windows associations for common MATLAB file types.
1 Startup and Shutdown Assume that when you double-click a .mat file in Windows Explorer, it opens in Microsoft Access, but you want the file to open in MATLAB. 1 In Windows Explorer, select Tools > Folder Options. 2 In the resulting Folder Options dialog box, select the File Types tab. From the Registered file types list, select the MAT extension. (If you do not see MAT in the list, click New to add it.) Under Details for ’MAT’ extension, click Change.
Starting MATLAB on Macintosh Platforms Starting MATLAB on Macintosh Platforms In this section... “Starting MATLAB from the Macintosh Desktop” on page 1-7 “Starting MATLAB from an M-File or Other File Type on Macintosh Platforms” on page 1-7 Starting MATLAB from the Macintosh Desktop To start MATLAB on Macintosh platforms, double-click the MATLAB icon on the desktop. If there isn’t a MATLAB icon on the desktop, you can find it in the MATLAB folder within the Applications folder.
1 Startup and Shutdown Startup Directory for MATLAB In this section... “What Is the Startup Directory?” on page 1-8 “Startup Directory (Folder) on Windows Platforms” on page 1-8 “Startup Directory on UNIX Platforms” on page 1-9 “Changing the Startup Directory” on page 1-9 What Is the Startup Directory? The startup directory is the current directory in MATLAB when it starts. The default startup directory depends on your platform and installation. You can specify a different startup directory.
Startup Directory for MATLAB Startup Directory on UNIX Platforms On UNIX platforms, the default startup directory is the directory you are in on your UNIX file system when you start MATLAB, for example, /home/$user/matlab. MATLAB automatically adds this matlab directory to the top of the MATLAB search path upon startup. Changing the Startup Directory You can start MATLAB in a directory other than the default.
1 Startup and Shutdown In the Start in field, enter the full path to the directory in which you want MATLAB to the start. For example, I:\my_matlab_files. The next time you start MATLAB using that shortcut icon, the current directory will be the one you specified in step 2.
Startup Directory for MATLAB You can make multiple shortcuts to start MATLAB, each with its own startup directory, and with each startup directory having different startup options. For All Platforms To change the startup directory, 1 Create a startup.m file — see “Using the Startup File for MATLAB, startup.m” on page 1-12. 2 In the startup.m file, include the cd function to change to the new directory. 3 Put the startup.
1 Startup and Shutdown Startup Options In this section... “About Startup Options” on page 1-12 “Using the Startup File for MATLAB, startup.m” on page 1-12 “Adding Startup Options for Windows Platforms” on page 1-13 “Adding Startup Options for UNIX Platforms” on page 1-14 “Commonly Used Startup Options” on page 1-14 About Startup Options You can define startup options that instruct MATLAB to perform certain operations when you start it. You specify these options using a startup file (startup.
Startup Options Adding Startup Options for Windows Platforms You can add selected startup options (also called command flags or switches for the command line) to the target path for your Windows shortcut for MATLAB. Or you can add them to the command line when you start MATLAB in a DOS window. On Windows systems a startup option is preceded by either a hyphen (-) or a slash (/). For example, -nosplash and /nosplash are equivalent ways of specifying the nosplash option for Windows users.
1 Startup and Shutdown ... matlab.exe -nosplash -r "results" Startup Options in DOS Window When you start MATLAB in a DOS window, include startup options after the matlab command.
Startup Options Platform Option Description UNIX -nodesktop Start MATLAB without bringing up the MATLAB desktop. Use this option to run without an X-window, for example, in VT100 mode, or in batch processing mode. Note that if you pipe to MATLAB using the > constructor, the nodesktop option is used automatically. With nodesktop, you can still use most development environment tools by starting them via a function.
1 1-16 Startup and Shutdown Platform Option Description All -nosplash Start MATLAB without displaying the MATLAB splash screen. All -r "statement" Automatically run the specified MATLAB statement immediately after MATLAB starts. This is sometimes referred to as calling MATLAB in batch mode. Files you run must be in the MATLAB startup directory or on the MATLAB search path. Do not include pathnames or file extensions. Enclose the statement in double quotation marks ("statement").
Toolbox Path Caching in MATLAB Toolbox Path Caching in MATLAB In this section... “About Toolbox Path Caching” on page 1-17 “Using the Cache File Upon Startup” on page 1-17 “Updating the Cache and Cache File” on page 1-17 “Additional Diagnostics with Toolbox Path Caching” on page 1-20 About Toolbox Path Caching For performance reasons, MATLAB caches toolbox directory information across sessions. The caching features are mostly transparent to you.
1 Startup and Shutdown We strongly recommend that you save any M-files you create and any MathWorks supplied M-files that you edit in a directory that is not in the matlabroot/toolbox directory tree. If you keep your files in matlabroot/toolbox directories, they may be overwritten when you install a new version of MATLAB. When to Update the Cache When you add files to matlabroot/toolbox directories, the cache and the cache file need to be updated.
Toolbox Path Caching in MATLAB Function Alternative To update the cache, use rehash toolbox. To also update the cache file, use rehash toolboxcache. For more information, see rehash.
1 Startup and Shutdown Additional Diagnostics with Toolbox Path Caching To display information about startup time when you start MATLAB, select the Enable toolbox path cache diagnostics check box in General Preferences.
Other Startup Topics Other Startup Topics In this section... “Error Log Reporter” on page 1-21 “Passing Perl Variables on Startup” on page 1-21 “Startup and Calling Java from MATLAB” on page 1-22 Error Log Reporter Upon startup, if MATLAB detects an error log generated by a serious problem encountered during the previous session, an Error Log Reporter prompts you to e-mail the log to The MathWorks for analysis. Click Send Report to e-mail the log, or click Help for more information.
1 Startup and Shutdown #!/usr/local/bin/perl $val = 10; system('matlab -r "test(' . ${val} . ')"'); 2 Invoke the Perl script at the prompt using a Perl interpreter. For more information, see the matlab (Windows) or matlab (UNIX) reference page. Startup and Calling Java from MATLAB When MATLAB starts, it constructs the Java class path using librarypath.txt as well as classpath.txt.
Quitting MATLAB Quitting MATLAB In this section... “Ways to Quit MATLAB” on page 1-23 “Confirm Quitting MATLAB” on page 1-23 “Running a Script When Quitting MATLAB” on page 1-24 “Abnormal Termination” on page 1-24 Ways to Quit MATLAB To quit MATLAB at any time, do one of the following: • Click the Close box in the MATLAB desktop. • Select Exit MATLAB from the desktop File menu. • Type quit at the Command Window prompt.
1 Startup and Shutdown For more information, see “Confirmation Dialogs Preferences” on page 2-81. You can also display your own quitting confirmation dialog box using a finish.m script, as described in the following section. Running a Script When Quitting MATLAB When MATLAB quits, it runs the script finish.m, if finish.m exists in the current directory or anywhere on the MATLAB search path. You create the file finish.m.
Quitting MATLAB make note of what seems to cause it and look for information about it in the MathWorks Bug Reports database. There are some situations where the Error Log Reporter will not open, for example, when you start MATLAB with a -r option or run in deployed mode.
1 1-26 Startup and Shutdown
2 Desktop If you have an active Internet connection, you can watch the Working in the Development Environment video demo for an overview of the major functionality. The easiest way to learn to use the desktop is just by working with it. If you have problems or questions, refer to the following sections. Overview of the Desktop (p. 2-3) Basic summary of the desktop and its tools. Arranging the Desktop (p. 2-6) Open and arrange desktop tools and documents to suit your needs.
2 2-2 Desktop Fonts Preferences for Desktop Tools (p. 2-62) Use desktop font preferences to specify the font characteristics for MATLAB desktop tools. Colors Preferences for Desktop Tools (p. 2-70) Set desktop color preferences for desktop tools, including syntax highlighting. General Preferences for MATLAB (p. 2-76) Set options for toolbox path caching, figure window printing, delete function behavior, MAT-file save format, confirmation dialogs, source control system, and multithreaded computation.
Overview of the Desktop Overview of the Desktop In this section... “About the Desktop” on page 2-3 “Summary of Desktop Tools” on page 2-5 About the Desktop In general, when you start MATLAB, it displays the MATLAB desktop, a set of tools (graphical user interfaces or GUIs) for managing files, variables, and applications associated with MATLAB. The first time you start MATLAB, the desktop appears with the default layout, as shown in the following illustration.
2 Desktop Menus change, depending on the tool you are using. Click the Start button for quick access to tools and more. 2-4 Select the title bar for a tool to use that tool. View or execute previously run statements. Get help. View or change the current directory. Drag the separator bar to resize windows. Move, maximize, minimize or close a window. Enter MATLAB statements at the prompt.
Overview of the Desktop Summary of Desktop Tools The following tools are managed by the MATLAB desktop, although not all of them appear by default when you first start. If you prefer a command-line interface, you can often use equivalent functions to accomplish the same result. To perform the equivalent of the GUI tasks in M-files, you must use the equivalent function.
2 Desktop Arranging the Desktop In this section... “Modifying the Desktop Configuration” on page 2-6 “Opening and Arranging Tools” on page 2-6 “Opening and Arranging Documents” on page 2-8 “Saving Desktop Layouts” on page 2-13 See also “Examples of Desktop Arrangements” on page 2-15. Modifying the Desktop Configuration You can modify the desktop configuration to best meet your needs.
Arranging the Desktop Tool Action Steps to Perform Navigating among desktop tools The Window menu displays all open desktop tools and documents, as well as opened tools for other MathWorks products. Select an entry in the Window menu to go directly to that tool or document. Another way to access an undocked desktop tool is by selecting its entry in the Windows task bar, or the equivalent for your platform. See also “Keyboard Shortcuts” on page 2-40 and more details online.
2 Desktop Tool Action Steps to Perform Grouping tools together You can group tools so that they overlay each other in the MATLAB desktop. To group tools together, drag the title bar of one tool in the desktop on top of the title bar of another tool in the desktop. To make a tool active, click its name in the title bar. See more details online.
Arranging the Desktop Example of Documents in the Desktop Some common actions for working with documents in the desktop are • Use the document bar to go to open documents. • Use the Window menu or equivalent toolbar buttons to position documents. • Close or undock a tool, including all documents in the tool. • Undock a document from its tool. • Use the document Close box with the Ctrl key to close the document without saving it and without displaying the unsaved document dialog box.
2 Desktop Close, undock, or resize tool (Editor/Debugger), including all open documents. Position documents within the tool using these options. Use document bar to go to open documents. Click name in title bar to go to open tool. 2-10 Undock document from tool, or close document.
Arranging the Desktop Summary of Actions for Arranging Documents This table summarizes actions for arranging documents in their tool. For further information, click the click the “see more details online” links. Document Action Overview Opening documents When you open a MATLAB document, it opens in the associated tool. If the tool is not already open, it opens when you open the document and appears in the position it occupied when last used.
2 Desktop Document Action Overview Navigating among documents — the document bar When more than one document is open within a tool, each document is either maximized (the default), or arranged so that multiple documents are visible at once. Click a document that is in view to make it the active document. See also “Keyboard Shortcuts” on page 2-40. Use the document bar to go to a document that is open but not in view. The names of all open documents appear in the document bar.
Arranging the Desktop Document Action Overview Closing documents To close a document, click the Close box in the document’s title bar. After closing all the documents in a tool, the tool remains open with no documents in it. If you select the Close box for the tool, all documents in that tool close. In the Editor/Debugger, when you close a file that has unsaved changes, a prompt appears asking if you want to save the document.
2 Desktop To use a predefined layout, select Desktop > Desktop Layout, and choose a configuration. See more details in the online documentation. To save your own layouts for later reuse, select Desktop > Save Layout and provide a name. To reuse a saved layout, select the name from Desktop > Desktop Layout. See more details in the online documentation.
Examples of Desktop Arrangements Examples of Desktop Arrangements In this section...
2 Desktop About These Examples Scan the illustrations in the following examples for a desktop arrangement similar to what you want, and then follow the brief instructions to achieve the arrangement. There are many different ways to accomplish the result; these instructions present just one way. The instructions might not apply exactly, depending on how your desktop looks before you start.
Examples of Desktop Arrangements Help browser is undocked from desktop to provide a large area for viewing documentation when needed. Four tools in the desktop are grouped together, providing a large area for working with a given tool. Click a tool's name in the title bar to make that tool active.
2 Desktop Maximized Tool in Desktop Example This example shows a way you can temporarily increase the size of a tool so that it occupies the entire area of the desktop. In this example, the Command Window in the default desktop layout is temporarily maximized by clicking the Maximize button in the tool’s title bar. Default desktop layout. Maximize a tool, for example, the Command Window so it occupies the full MATLAB desktop area.
Examples of Desktop Arrangements Maximized, the Command Window now occupies the full desktop area. Restoring the Command Window returns it to its original size and location in the desktop.
2 Desktop Minimized Tools in Desktop Example Minimize a tool in the desktop to give the remaining desktop tools more space in the desktop. Minimizing is available on Windows and UNIX platforms. In this example, the Command History in the default layout is being minimized to the left edge of the desktop. Minimize a tool, for example, the Command History window. In this illustration, the Command History has been minimized and appears as a button along the left edge.
Examples of Desktop Arrangements When minimized, a tool, such as the Command Window in this example, is represented by a button on the desktop border. This illustration shows the minimized Command History being temporarily opened, as a result of clicking or hovering over the button.
2 Desktop Hover over or click the button for a minimized tool to temporarily view or use the tool. The tool is temporarily displayed until you select another tool. Then the tool becomes minimized again. After using the Command History and clicking the button, or moving on to another tool, the Command History again becomes minimized as a button along the left edge.
Examples of Desktop Arrangements On the button for a minimized tool, right-click, and from the context menu,select Restore. The tool resumes the size and position it had in the desktop before it was minimized.
2 Desktop Tiled Documents in Desktop Example When you open a document (for example, an M-file), it also opens the tool (for example, the Editor/Debugger) if the tool is not already opened. Subsequent documents of the same type open in the tool and you can then arrange the documents within the tool. You can move a document on top of another document, so that the one on top hides the one(s) beneath it, or you can show multiple documents at once.
Examples of Desktop Arrangements The shortcuts toolbar is hidden. The document bar is at the top edge of the Editor/Debugger. Select a button from the list to arrange the documents, such as Left/Right Tile.
2 Desktop No Empty Document Tiles Example To see more than two documents at once, select the Tile button and move the pointer across the gird that appears to select the number of tiles you want. The following “Before” illustration has four tiles, but only three documents are open. (The empty tile is gray.) You can move a document to any empty tile by dragging its title bar to the new location. To close an empty tile, position the pointer over the handle on the separator bar.
Examples of Desktop Arrangements Maximized Documents Outside of the Desktop Example This example illustrates a way to provide a large area for multiple documents, in this case, M-files maximized in the undocked Editor/Debugger. Some common actions for working with documents outside of the desktop are • Group all Editor/Debugger documents together — select Desktop > Dock All in Editor from any Editor/Debugger document.
2 Desktop • Access any document in the Editor/Debugger using the document bar. To show the document bar on the left side of the Editor/Debugger, select Desktop > Bar Position > Document Bar > Left from the Editor/Debugger. Floating (Cascaded) Figures in Desktop Example This example illustrates multiple figures in the desktop. By default, figures open outside the desktop. Click the Dock button in each figure’s menu bar to move the figures into the desktop.
Examples of Desktop Arrangements Dock figures in the desktop and use the float option to arrange them within a Figures group. The document bar is hidden.
2 Desktop Undocked Tools and Documents Example You can use tools and documents outside of the desktop. One way to achieve this is to first undock the tool from the desktop by selecting Desktop > Undock Toolname. Then undock documents from the undocked tool by selecting Desktop > Undock Documentname from the tool. If you undock all documents from a tool, an “empty” tool window remains. In this example, one of the Editor/Debugger documents, collatz.
Examples of Desktop Arrangements 2-31
2 Desktop Shortcuts for MATLAB — Easily Run a Group of Statements In this section... “What Is a Shortcut?” on page 2-32 “Examples of Useful Shortcuts” on page 2-32 “Creating Shortcuts” on page 2-33 “Running Shortcuts” on page 2-35 “Shortcuts Toolbar” on page 2-35 “Organizing and Editing Shortcuts” on page 2-38 What Is a Shortcut? A MATLAB shortcut is an easy way to run a group of MATLAB statements that you use regularly. First you create a shortcut that contains all the statements.
Shortcuts for MATLAB — Easily Run a Group of Statements create a shortcut for even a single function they use frequently, such as clc to clear the Command Window. • Create a shortcut to set the same properties for figures you create, such as adding a legend and setting the background color. • Create a shortcut for a long statement, such as changing the current directory (cd) when the pathnames are long. • Create a shortcut for a statement you do not easily remember but need to use.
2 Desktop the Editor/Debugger preferences for key bindings, colors, and fonts. Note that if you copy the statements from the Command Window, the prompt appears in the shortcut, but MATLAB removes the prompt when you save the shortcut. c Assign a category, which is like a directory for organizing shortcuts. Specify sea_temp_project. To add the shortcut to the shortcuts toolbar, select the Toolbar Shortcuts category. d Use the default shortcuts icon , or select your own. e Click Save.
Shortcuts for MATLAB — Easily Run a Group of Statements For more information on the options in the Shortcut Editor dialog box, click the Help button. Additional Ways to Create Shortcuts You can also use these methods to create shortcuts: • Add shortcuts to and run them from the desktop Shortcuts toolbar. See “Shortcuts Toolbar” on page 2-35. • From the Command History window, create a shortcut by selecting statements, right-clicking, and selecting Create Shortcut from the context menu.
2 Desktop 1 Select statements from the Command History window, the Command Window, or an M-file. 2 Drag the selection to the desktop Shortcuts toolbar. The following illustration shows two statements being dragged from the Command Window. 3 The Shortcut Editor dialog box appears. The Callback field contains the selected statements, which you can edit as needed. If prompts (>>) from the Command Window appear, note that MATLAB automatically removes them when you save the shortcut.
Shortcuts for MATLAB — Easily Run a Group of Statements 4 Click the icon on the Shortcuts toolbar to run the shortcut. You can also run the shortcut from the Start button by selecting it in the Toolbar Shortcuts category. You can also add a shortcut to the desktop Shortcuts toolbar by right-clicking the toolbar and selecting New Shortcut. Complete the resulting Shortcut Editor dialog box. Assuming you maintain the Toolbar Shortcuts category, the shortcut appears on the toolbar.
2 Desktop When you move the mouse over a shortcut icon, its label appears as a tooltip. To make labels display in the toolbar, right-click the toolbar and select Show Labels, which adds a check mark next to the item and displays the labels. Organizing and Editing Shortcuts To create categories for shortcuts, and to move, edit, and delete shortcuts, perform these steps: 1 Select Shortcuts > Organize Shortcuts from the Start button. Alternatively, access it via the shortcuts toolbar context menu.
Shortcuts for MATLAB — Easily Run a Group of Statements Changes take effect immediately. 3 Click Close. For more information about using the Shortcuts Organizer dialog box, click the Help button.
2 Desktop Keyboard Shortcuts In this section... “Keyboard Shortcuts (Accelerators or Hot Keys) and Mnemonics” on page 2-40 “Go To First Letter (Type Ahead) Feature in Desktop Tool Lists” on page 2-42 “Default Button and Active Button (Button with Focus)” on page 2-42 Keyboard Shortcuts (Accelerators or Hot Keys) and Mnemonics You can access many of the menu items using shortcut keys (sometimes called accelerators or hot keys) for your platform.
Keyboard Shortcuts Windows 2000, go to Display Control Panel, select Effects, and clear the item Hide keyboard navigation indicators until I use the Alt key. See your Windows documentation for details. Following are some general shortcuts that are not listed on menu items. Key Result Enter The equivalent of double-clicking, Enter performs the default action for a selection. For example, press Enter while a statement in the Command History window is selected to run that statement in the Command Window.
2 Desktop Key Result Ctrl+Shift+Tab Moves to the previous open tool or group of tabbed tools in the desktop. Ctrl+Page Down Moves to the next tool within a group of tools tabbed together. In a group of documents, moves to next document. Ctrl+Page Up Moves to the previous tool within a group of tools tabbed together. In a group of documents, moves to previous document. Ctrl+F6 Moves to the next tool or document (only for Windows and Solaris platforms).
Keyboard Shortcuts 2-43
2 Desktop Other Desktop Features In this section...
Other Desktop Features 2 From the menu and submenu items, select an item to open it. Use the icons to quickly locate a type of product or tool — see the following description of icons. For example, select Start > MATLAB > GUIDE (GUI Builder) to open that tool. Icons in the Start Button. Icons help you quickly locate a particular type of product or tool. This table describes the action performed when you select an entry with one of these icons in the Start button.
2 Desktop Icon Description of Action When Opened Block library opens. Document opens in your system Web browser. Customizing the Start Button You can add your own toolboxes to the Start button. Select Start > Desktop Tools > View Source Files to open the Start Button Configuration Files dialog box. For more information, click the Help button in the dialog box. Menus and Context Menus Merged Menus When you use a tool in the desktop, its menu appears at the top of the desktop.
Other Desktop Features Toolbars The toolbar in the desktop provides easy access to frequently used operations. Position the pointer over a button for a second or two and a tooltip appears that describes the item.
2 Desktop Some tools also have their own toolbars, which are located within the tool’s own window. For example, the Current Directory browser has its own toolbar. When you undock one of these tools, the undocked tool includes the toolbar. To hide a toolbar, or to show it again after hiding it, use the appropriate toolbar item in the Desktop menu. As an alternative, right-click a toolbar or menu bar and select a toolbar from the context menu to hide or show it.
Other Desktop Features Status Bar Along the bottom of the desktop is the status bar. It displays messages, such as when MATLAB is busy executing statements or when the Profiler is on. Some tools, such as the Editor/Debugger, display additional status information, such as the current line number. Not all status information appears on the status bar — many MATLAB functions and tools provide status information that is not reported to the status bar.
2 Desktop Selecting Multiple Items In many desktop tools, you can select multiple items and then select an action to perform on all the selected items. Select multiple items using the standard practices for your platform. For example, if your platform is Windows, do the following to select multiple items: 1 Click the first item you want to select. 2 Hold the Ctrl key and then click the next item you want to select. Repeat this step until you have selected all the items you want.
Other Desktop Features Cut, Copy, Paste, and Move You can cut and copy a selection from a desktop tool to the clipboard and then paste it from the clipboard into another tool or application. Use the Edit menu, toolbar, context menus, or standard keyboard shortcuts. For example, you can copy a selection of statements from the Command History window and paste them into some MATLAB desktop tools. Use Paste to move items copied to the clipboard from other applications.
2 Desktop can drag selections from desktop tools to other applications. For example, you can drag text from the Editor/Debugger to Microsoft Word. Macintosh Differences in the Desktop MATLAB on the Macintosh platform sometimes uses Macintosh GUI conventions, which might be different from what is stated in the MATLAB documentation, but the intended action should be clear. For example, if you select File > Save on the Macintosh, the Save dialog box that appears presents the options Don’t Save and Save.
Other Desktop Features • “Fonts Options for Page Setup” on page 2-54 Specifying Page Setup Options To specify page setup options, perform these steps: 1 In the tool you want to print from, for example, the Command Window, select File > Page Setup. The Page Setup dialog box opens for that tool. 2 Click the Layout, Header, or Fonts tab in the dialog box and set those options for that tool, as detailed in subsequent sections. 3 Click OK.
2 Desktop Layout Options for Page Setup You can specify the following layout options. A preview area shows you the effects of your selections: • Print header — Print the header specified in the Header pane. • Print line numbers — Print line numbers. • Wrap lines — Wrap any lines that are longer than the printed page width. • Syntax highlighting — For keywords and comments that are highlighted in the Command Window, specify how they are to appear in print.
Other Desktop Features 3 Repeat for the other element. If you did not select Print header on the Layout pane, you do not need to specify the Header font. As an example, for Header text, select Use custom font and then specify the font characteristics — type, style, and size. After you specify a custom font, the Sample area shows how the font will look. Web Browser Some tools in MATLAB and related products display HTML documents in the MATLAB Web Browser.
2 Desktop The toolbar buttons and menu items in the Web Browser are similar to those found in the Help browser display pane. For more information, see “Viewing Documentation in the Help Browser” on page 4-26. One feature of the Web Browser not found in the Help browser is the Location field. In the Web Browser, type a URL in the field to display that Web page. Like any Web browser, the MATLAB Web Browser might not support all of the HTML or related features used in a particular Web site or HTML page.
Other Desktop Features For most items, the selected Web page then opens in your default system Web browser, for example, Netscape: • The MathWorks Web Site — Home page of the MathWorks Web site (http://www.mathworks.com). • Products & Services — MathWorks Products and Services page (http://www.mathworks.com/products/) with information about the full family of products. • Support — MathWorks Support page (http://www.mathworks.
2 Desktop users. MATLAB Digest, an electronic bulletin consisting of technical notes, solutions, and timely announcements to the user community, is issued more frequently. See http://www.mathworks.com/company/newsletters. Check for Updates This features allows you to easily determine if more recent versions of your MathWorks products are available. Select Help > Check for Updates. A dialog box appears, listing the version numbers of all MathWorks products installed on your system.
Preferences Preferences In this section... “Setting Preferences” on page 2-59 “Summary of Preferences” on page 2-60 “Preferences File — matlab.prf” on page 2-61 Setting Preferences Use preferences to specify options for MATLAB tools, as follows: 1 Select File > Preferences. 2 In the left pane of the Preferences dialog box, preferences appear for MATLAB tools as well as for any other MathWorks products installed on your system. Choose a tool and click the + to display more preferences for that tool.
2 Desktop Summary of Preferences 2-60 Preference What You Can Specify General Preferences Toolbox path caching, figure window printing, delete function behavior, MAT-file save formats, confirmation dialogs, source control, and multithreaded computation. Keyboard Key bindings, tab completion, and delimiter matching for the Command Window and the Editor/Debugger. Fonts Font type, style, and size for desktop tools. Customize for any tool.
Preferences Preferences File — matlab.prf Preferences are stored in a preferences file, matlab.prf. Type prefdir in the Command Window to see the full pathname for the preferences directory that contains matlab.prf. The preference directory also contains related files. On Macintosh platforms, the directory might be in a hidden folder, for example, myname/.matlab/R2007b. To access the directory, select Go > Go to Folder in the Mac OS Finder.
2 Desktop Fonts Preferences for Desktop Tools In this section... “Setting Desktop Fonts” on page 2-62 “Desktop Code Font and Desktop Text Font” on page 2-63 “Custom Fonts Preferences” on page 2-67 “Changing the Font — Example” on page 2-68 “Antialiasing for Desktop Fonts on Linux/UNIX” on page 2-69 “Making Fonts Available to MATLAB” on page 2-69 Setting Desktop Fonts Use desktop font preferences to specify the font characteristics for MATLAB desktop tools.
Fonts Preferences for Desktop Tools Desktop Code Font and Desktop Text Font You specify separate font characteristics for tools that primarily display code (Desktop code font), such as the Command Window, and tools that primarily display text (Desktop text font), such as the Current Directory 2-63
2 Desktop browser. Many users prefer that code display in a monospace font to provide better alignment, and prefer a more narrow font style for text information. With the desktop code font preference, you set just one preference to apply a monospace style to all tools that display code (except the Help and Web Browsers). Similarly, you can set just one preference to apply a text font to all desktop tools that display text.
Fonts Preferences for Desktop Tools Default Font Settings Default settings are listed in the following table. Note that Lucida Console approximates the fixedsys font available in earlier versions of MATLAB.
2 Desktop Font Type Default Characteristics and Sample Tools Using Font Type by Default Desktop code font Monospaced, Plain, 10 point • Command History • Command Window • Editor/Debugger (which also applies to the Shortcuts Editor) Desktop text font SansSerif, Plain, 10 point • Array Editor • Current Directory browser (which also applies to the Path browser) • Help Navigator • HTML Proportional Text.
Fonts Preferences for Desktop Tools Custom Fonts Preferences If you do not want to use the current settings for “Desktop Code Font and Desktop Text Font” on page 2-63, you can specify that a tool use the code font, the text font, or a different font. Select File > Preferences > Fonts. Click + and select Custom. The Fonts Custom Preferences pane appears. Select a tool from the Desktop tools list. The type of font it uses, code or text, appears under Font to Use.
2 Desktop To change the font characteristics the selected tool uses, select a different radio button. For Custom, you then specify the font characteristics for that tool.
Fonts Preferences for Desktop Tools Tool Font Type Font Characteristics Workspace Desktop text SansSerif, Plain, 10 point Array Editor Desktop text SansSerif, Plain, 10 point See Also For help about how MATLAB stores preferences and help for other preferences, see “Preferences” on page 2-59. Antialiasing for Desktop Fonts on Linux/UNIX To give the desktop a smoother appearance in Linux/UNIX, select the antialiasing preference on the Preference > Fonts pane. The preference apply to all fonts.
2 Desktop Colors Preferences for Desktop Tools In this section... “Setting Colors Used in Desktop Tools” on page 2-70 “Desktop Tool Colors” on page 2-72 “Syntax Highlighting Colors” on page 2-73 “Other Colors” on page 2-75 “See Also” on page 2-75 Setting Colors Used in Desktop Tools Desktop color preferences specify the colors used in MATLAB desktop tools and the colors that convey syntax highlighting. Select File > Preferences > Colors to set color preferences for desktop tools.
Colors Preferences for Desktop Tools To set colors for text and the background, clear the Use system colors check box and then select colors from the palettes. Specify the color of hyperlinks in the Command Window and Help browser Index pane.
2 Desktop Desktop Tool Colors Use Desktop tool colors to change the color of the text and background in the desktop tools. The colors also apply to the Import Wizard. The colors do not apply to the HTML display pane nor to the Web Browser. Select the check box Use system colors if you want the desktop to use the same text and background colors that your platform (for example, Windows) uses for other applications.
Colors Preferences for Desktop Tools Gray Background Color For some UNIX platforms, there is a gray background color for desktop tools, such as the Editor/Debugger. This occurs when the preference for Desktop tool colors is set to Use system colors, and the system’s window manager uses gray as the background color default. To change the color, clear the check box for Use system colors and then select a new Background color from the palette.
2 Desktop The default colors are listed here: • Keywords — Flow control functions, such as for and if, as well as the continuation ellipsis (...), are colored blue. • Comments — All lines beginning with a %, designating the lines as comments in MATLAB, are colored green. Similarly, the block comment symbols, %{ and %}, as well as the code in between, appear in green. Text following the continuation ellipsis on a line is also green because it is a comment.
Colors Preferences for Desktop Tools Other Colors Specify the color for Hyperlinks, which applies to links in the Command Window and Help browser Index pane. If you use a dark background color for those tools, be sure to use a light or other contrasting color for hyperlinks so that you can see them. With the M-Lint autofix highlight preference selected, code that M-Lint can automatically correct is highlighted in the Editor/Debugger. Use the palette to change the highlight color.
2 Desktop General Preferences for MATLAB In this section... “Setting General Preferences for MATLAB” on page 2-76 “Default Behavior of the Delete Function” on page 2-78 “MAT-Files Preferences” on page 2-79 “Confirmation Dialogs Preferences” on page 2-81 “Multithreading Preferences” on page 2-84 Setting General Preferences for MATLAB Select File > Preferences > General from any desktop tool to access General Preferences.
General Preferences for MATLAB These preferences apply to all relevant tools in MATLAB.
2 Desktop • “MAT-Files Preferences” on page 2-79 • “Confirmation Dialogs Preferences” on page 2-81 • Chapter 9, “Source Control Interface” • “Multithreading Preferences” on page 2-84 Default Behavior of the Delete Function Files you delete using the delete function are permanently removed by default. There is no opportunity to retrieve them. You can use this preference to instead move deleted files to the Recycle Bin on Windows, to the Trash Can on Macintosh, or to a tmp directory on UNIX platforms.
General Preferences for MATLAB MAT-Files Preferences The MAT-file save format sets the default version compatibility option MATLAB uses when saving MAT-files. Use these options if you use multiple versions of MATLAB or share MAT-files with others who run a different version of MATLAB. The setting applies when you use the save function as well as when you useSave menu items for MAT-files, such as File > Save Workspace As from any desktop tool.
2 Desktop allow it, which is the primary purpose of this option. Using this option is equivalent to running save -v7.3. This format of the resulting MAT-file is HDF5-based. You cannot load these MAT-files into any versions prior to MATLAB Version 7.3; in those cases, use one of the other two options. • MATLAB Version 7 or later (save -v7)—Starting in MATLAB Version 7, MATLAB compresses the data when saving a MAT-file, thereby reducing the storage space required.
General Preferences for MATLAB might be more convenient than changing the preference. For example, use save with the-v6 option to ensure compatibility with MATLAB versions prior to Version 7. For more information, see the save reference page. Confirmation Dialogs Preferences These preferences instruct MATLAB to display or not display specific confirmation dialog boxes. When the check box for a confirmation dialog is selected and you perform the action it refers to, the confirmation dialog box appears.
2 Desktop When the confirmation dialog box does appear, it includes a Do not show this prompt again check box. If you select the check box in the dialog box, it automatically clears the check box for the confirmation preference. For example, select the check box Warn before deleting Command History items. Then select Edit > Delete Selection in the Command History, MATLAB displays the following confirmation dialog box.
General Preferences for MATLAB Confirmation Dialogs Check Box Item About the Confirmation Dialog Box For More Information Prompt when editing files that do not exist Appears when you type edit filename, if filename does not “Function Alternative” on page 6-9 exist in the current directory or on the MATLAB path. Prompt to exit debug mode when saving file Appears when you try to save a modified file while in debug mode.
2 Desktop Multithreading Preferences If you run MATLAB on a multiple-CPU system (multiprocessor or multicore), you can use multithreaded computation, which can improve performance for some operations. For more information, see .
Accessibility Accessibility In this section... “Software Accessibility Support” on page 2-85 “Documentation Accessibility Support” on page 2-86 “Assistive Technologies” on page 2-87 “Installation Notes for Accessibility Support” on page 2-88 “Troubleshooting” on page 2-91 Software Accessibility Support MathWorks products includes a number of modifications to make them more accessible to all users.
2 Desktop Except for scopes and real-time data acquisition, the MathWorks software does not use flashing or blinking text, objects, or other elements having a flash or blink frequency greater than 2 Hz and lower than 55 Hz. The MathWorks believes that its products do not rely on auditory cues as the sole means of conveying information about working with a GUI. However, if you do encounter any issues in this regard, please report them to the MathWorks Technical Support group. http://www.mathworks.
Accessibility The following product documentation has been modified (as described below) to enhance its accessibility for people using a screen reader such as JAWS: • MATLAB (many sections, but not the function reference pages (however, M-file help is accessible)) • Excel Link • Optimization Toolbox • Signal Processing Toolbox • Statistics Toolbox Documentation Modifications Modifications to the documentation include the following: • Describing illustrations in text (either directly or via links) • Provid
2 Desktop • JAWS 5.0, 6.0, and 7.
Accessibility Setting Up JAWS Make sure that JAWS is installed on your machine. If it is, there is probably a shortcut to it on the Windows desktop. Setting up JAWS involves these tasks: 1 Add the Access Bridge to your Windows path (for networked installations only). 2 Create the accessibility.properties file. These tasks are described in more detail below. (For Networked Installations Only) Add Access Bridge to Your Path.
2 Desktop Be sure to include that semicolon between the end of this directory name and the text that was already there. 7 Click OK three times. 8 If JAWS is already running, exit and restart. Note JAWS must be started with these path changes in effect to work properly with MATLAB. Create the accessibility.properties File. 1 Create a text file that contains the following two lines: screen_magnifier_present=true assistive_technologies=com.sun.java.accessibility.
Accessibility 1 Start JAWS. 2 Start MATLAB. JAWS should start talking to you as you select menu items and work with the MATLAB user interface in other ways. Troubleshooting This section identifies workarounds for some possible issues you may encounter related to accessibility support in MathWorks products. JAWS Does Not Detect When the MATLAB Installation Has Started When you select setup.exe, the Windows copying dialog box opens and you are informed.
2 Desktop press the arrow keys to move to the command output and use JAWS keystrokes to read the output. With this preference set, you cannot use arrow keys to recall previous commands. Instead use the following key bindings: • Windows key bindings: - Previous history: Ctrl+up arrow Next history: Ctrl+down arrow • Emacs key bindings: - Previous history: Ctrl+p Next history: Ctrl+n To return to using the up and down arrow keys to recall previous commands, clear the preference.
3 Running Functions — Command Window and History If you have an active Internet connection, you can watch the Working in the Development Environment video demo and the Command History video demo for an overview of the major functionality. The Command Window is where you run (execute) MATLAB statements, while the Command History is a log of the statements you have run. The Command Window (p. 3-3) Access the Command Window. Running Functions and Programs, and Entering Variables (p.
3 3-2 Running Functions — Command Window and History Preferences for the Command Window (p. 3-40) Specify options for text, display, tab size, accessibility, and indenting for the Command Window and the Editor/Debugger. Command History Window (p. 3-49) View session histories. Run statements, copy entries, search, and print the history. Set preferences. Preferences for Command History (p. 3-59) Specify how often to automatically save the history file and the types of statements to exclude.
The Command Window The Command Window In this section... “About the Command Window” on page 3-3 “Opening the Command Window” on page 3-3 “Command Window Prompt” on page 3-4 “Getting Started Message Bar in the Command Window” on page 3-5 About the Command Window The Command Window is one of the main tools you use to enter data, run MATLAB functions and other M-files, and display results.
3 Running Functions — Command Window and History Command Window Prompt The Command Window prompt, >>, is where you enter statements. For example, you can enter a MATLAB function with arguments, or assign values to variables. The prompt indicates that MATLAB is ready to accept input from you. When you see the prompt, you can enter a variable or run a statement. This prompt is also known as the command line. When MATLAB displays the K>> prompt in the Command Window, MATLAB is in debug mode.
The Command Window Getting Started Message Bar in the Command Window Just below the Command Window menu bar is a message bar that includes links to a video, demos, and information on getting started with MATLAB. If you want to remove the message bar in the Command Window, click the Close box in the right corner of the bar. If after having closed it, you want to display the information bar again, use “Preferences for the Command Window” on page 3-40.
3 Running Functions — Command Window and History Help for Functions” on page 4-49—for more general information on help, see Chapter 4, “Help for Using MATLAB”.
Running Functions and Programs, and Entering Variables Running Functions and Programs, and Entering Variables In this section... “Running Statements at the Command Line Prompt” on page 3-7 “Running External Programs” on page 3-9 “Evaluating or Opening a Selection” on page 3-12 “Displaying Hyperlinks in the Command Window” on page 3-13 Running Statements at the Command Line Prompt Entering Variables and Running Functions At the prompt, enter data and run functions.
3 Running Functions — Command Window and History Definition of a Statement. All of the information you type before pressing Enter or Return is known as a statement. This can include: • Variable assignments: For example, a = 3 • Commands: M-files provided with MATLAB or toolboxes that do not accept input arguments, for example, clc, which clears the Command Window. • Scripts: M-files (MATLAB program files) you write that do not take input arguments or return output arguments, for example, myfile.m.
Running Functions and Programs, and Entering Variables the MATLAB current directory or on the MATLAB search path — for details, see “Search Path” on page 5-23. You can also use the run function and specify the full pathname to an M-file script. To determine the name of the M-file currently running, use mfilename. Examining Errors If an error message appears when you run an M-file, click the underlined portion of the error message, or position the cursor within the filename and press Ctrl+Enter.
3 Running Functions — Command Window and History !vi yearlystats.m invokes the vi editor for a file named yearlystats.m. After the external program completes or you quit the program, the operating system returns control to MATLAB. Add & to the end of the line, such as !dir & on Windows platforms to display the output in a separate window or to run the application in background mode. For example !excel.
Running Functions and Programs, and Entering Variables UNIX System Path and Running UNIX Programs from MATLAB To run a UNIX program from MATLAB if its directory is not on the UNIX system path MATLAB uses, take one of the actions described here. Change Current Directory in MATLAB. Change the current directory in MATLAB to the directory that contains the program you want to run. Modify the UNIX System Path MATLAB Uses. Add the directories to the system path from the shell.
3 Running Functions — Command Window and History 3 Save the file. The matlab file will modify the PATH environment variable, and then start MATLAB. Evaluating or Opening a Selection Make a selection in the Command Window and press Enter or Return. The selection is appended to whatever is at the prompt, and MATLAB executes it. Similarly, you can select a statement from any MATLAB desktop tool, right-click, and select Evaluate Selection from the context menu.
Running Functions and Programs, and Entering Variables Displaying Hyperlinks in the Command Window You can use MATLAB commands to create hyperlinks in the Command Window. The created hyperlink can: • Open a Web page in a MATLAB browser using an href string. • Transfer files via the file transfer protocol (FTP). • Run a MATLAB M-file using the matlabcolon (matlab:) command.
3 Running Functions — Command Window and History Running MATLAB Functions by Hyperlink Use matlab: to run a specified statement when you click a hyperlink in the Command Window. For example disp('Generate magic square') displays When you click the link Generate magic square, MATLAB runs magic(4). Alternatively, you can press Ctrl+Enter if the cursor is positioned in the link text. You can use the disp, error, fprintf, or warning function with this feature.
Controlling Input Controlling Input In this section...
3 Running Functions — Command Window and History Note that if you use the help function, function names are shown in all uppercase, for example, PLOT, solely to distinguish them. Some functions for interfacing to Java do use mixed case and the M-file help and documentation accurately reflect that. Examples. The directory first is at the top of the search path and contains the file A.m. If you type a instead of A, MATLAB runs A.m but issues a warning.
Controlling Input Matching Delimiters (Parentheses) You can set a preference for MATLAB to notify you about matched and unmatched delimiters. For example, when you type a parenthesis, bracket, or brace, MATLAB highlights the matched delimiter in the pair. To set these preferences, select File > Preferences > Keyboard > Delimiter Matching. This feature is also available in the Editor/Debugger. For more information, see “Delimiter Matching” on page 3-46.
3 Running Functions — Command Window and History Enter Multiple Lines Without Running Them To enter multiple lines before running any of them, use Shift+Enter or Shift+Return after typing a line. This is useful, for example, when entering a set of statements containing keywords, such as if ... end. The cursor moves down to the next line, which does not show a prompt, where you can type the next line. Continue for more lines. Then press Enter or Return to run all of the lines.
Controlling Input headers = Author Last Name, Author First Name, Author Middle Initial MATLAB produces an error when you do not complete the string, as shown here: headers = ['Author Last Name, Author First Name, ... Author Middle Initial'] ??? headers = ['Author Last Name, Author First Name, ... Error: Missing variable or function. Note that MATLAB ignores anything appearing after the ... on a line, and continues processing on the next line.
3 Running Functions — Command Window and History again to display the next most recent line that began with plo, and so on. Then press Enter or Return to run the line. This feature is case sensitive. If the up arrow key moves the cursor up but does not recall previous lines, clear the accessibility preference. For more information, see “Accessibility” on page 3-43.
Controlling Input • “Tab Completion for Properties” on page 3-25 Basic Example — Unique Completion This example illustrates a basic use for tab completion. After creating a variable, costs_march, type costs and press Tab. MATLAB automatically completes the name of the variable, displaying costs_march Then complete the statement, adding any arguments, operators, or options, and press Return or Enter to run it. In this example, if you just press Enter, MATLAB displays the contents of costs_march.
3 Running Functions — Command Window and History The resulting list of possible completions includes the variable name you created, costs_march, but also includes functions that begin with cos, including cosets from Communications Toolbox, if it is installed on the system and on the MATLAB search path. MATLAB completes variable names in the currently selected workspace, and the names of functions and models on the MATLAB search path or in the current directory. Continue typing to make your entry unique.
Controlling Input Narrowing Completions Shown. You can narrow the list of completions shown by typing a character and then pressing Tab if the Command Window preference Tab key narrows completions is selected. This is particularly useful for large lists. For example, type cam and press Tab to see the possible completions. There is a scroll bar with the list because there are too many completions to be seen at once. Type p and press Tab again.
3 Running Functions — Command Window and History Continue narrowing the list in the same way. For the above example, type o and press Tab to further narrow the list. Press Enter or Return to select an item, which completes the name at the prompt. Tab Completion for Directories and Filenames Tab completion works for directories and filenames in MATLAB functions. For example, type edit d:/ and press Tab. MATLAB displays the list of directories and files in d, from which you can choose one.
Controlling Input For example, type mystruct.n and press Tab, which completes the entry mystruct.name, where mystruct contains no other fields that begin with n. Tab Completion for Properties Complete property names for figures in the current workspace using tab completion, as in this graphics example. Here, f is a figure. Type set(f, 'pap and press Tab. MATLAB displays Select a property from the list. For example, type u and press Enter. MATLAB completes the property, including the closing quote.
3 Running Functions — Command Window and History set(f, 'paperUnits', 'centimeters' because centimeters is the only possible completion. Keyboard Shortcuts in the Command Window Following is the list of arrow and control keys that serve as shortcuts for using the Command Window. In addition to these shortcut keys (sometimes called hot keys), you can use shortcuts for menu items, which you can view on the menus, as well as general desktop shortcuts described in “Keyboard Shortcuts” on page 2-40.
Controlling Input Key or Mouse Action for Windows Preference Control Key for MATLAB standard (Emacs) Preference Key or Mouse Action for Macintosh Preference Ctrl+N Operation Recall next line — for details, see “Recalling Previous Lines” on page 3-19. Works only after using the up arrow or Ctrl+P. With the Accessibility preference selected, moves the cursor down a line when it is above the prompt. In that event, use Ctrl+ to recall previous lines for Windows and Macintosh key bindings.
3 3-28 Running Functions — Command Window and History Key or Mouse Action for Windows Preference Control Key for MATLAB standard (Emacs) Preference Key or Mouse Action for Macintosh Preference Esc Ctrl+U Esc Clear the command line when cursor is at the command line. Otherwise, move cursor to command line. Delete Ctrl+D Forward Delete Delete character after cursor. Backspace Ctrl+H Delete Delete character before cursor.
Controlling Input Key or Mouse Action for Windows Preference Control Key for MATLAB standard (Emacs) Preference Key or Mouse Action for Macintosh Preference Shift+End None Shift+Cmd+ Select from cursor to end of statement. With Macintosh key bindings, select to end of line. Enter in selection None None Append selection to statement at command line and execute it. Ctrl+Enter in hyperlink None Ctrl+Enter in hyperlink Open hyperlink displayed in Command Window.
3 Running Functions — Command Window and History Controlling Output In this section... “Echoing Execution” on page 3-30 “Suppressing Output” on page 3-30 “Paging of Output in the Command Window” on page 3-30 “Formatting and Spacing Numeric Output” on page 3-31 “Clearing the Command Window” on page 3-32 “Printing Command Window Contents” on page 3-33 “Keeping a Session Log” on page 3-33 Echoing Execution To display each function within a statement as it executes, run echo on.
Controlling Output --more-- indicating there is more output to display. Press one of the following keys. Key Action Enter or Return To advance to the next line Space Bar To advance to the next page q To stop displaying the output You can scroll in the Command Window to see input and output that are no longer in view. As an alternative to scrolling, you can use the up and down arrow keys if the Command Window Accessibility preference is selected.
3 Running Functions — Command Window and History 1.3333e+000 1.2345e-006 format + ++ A complete list and description of available formats is in the reference page for format. For more control over the output format, use the sprintf and fprintf functions. Controlling Spacing To control spacing in the output, use the Command Window preference for text display or the format function. Use format compact to suppress blank lines, allowing you to view more information in the Command Window.
Controlling Output Printing Command Window Contents To print the complete contents of the Command Window, select File > Print. To print only a selection, first make the selection in the Command Window and then select File > Print Selection. Specify printing options for the Command Window by selecting File > Page Setup. For example, you can print with a header. For more information, see “Printing and Page Setup Options for Desktop Tools” on page 2-52.
3 Running Functions — Command Window and History Searching in the Command Window In this section... “Introduction” on page 3-34 “Find Dialog Box” on page 3-34 “Incremental Search” on page 3-35 Introduction You can search for specified text that appears in the Command Window, where the text was either part of input you supplied, or output displayed by MATLAB. After finding the desired text, you can copy and paste it to the prompt in the Command Window to run it, or into an M-file or other file.
Searching in the Command Window MATLAB beeps when a search for Find Next reaches the end of the Command Window, or when a search for Find Previous reaches the top of the Command Window. If you have Wrap around selected, it continues searching after beeping. Note that you can only search for text currently displayed in the Command Window.
3 Running Functions — Command Window and History 4 In the Inc Search field, type the text you want to find. For example, look for Boston. As you type the first letter, b, the first occurrence of that letter in the Command Window after the current cursor position is highlighted. For the example shown, the first occurrence of b is highlighted, the b in Berlin. Note that incremental search allows for case sensitivity — see “Case Sensitivity in Incremental Search” on page 3-38.
Searching in the Command Window When you type the next letter, the first occurrence of the text becomes highlighted. In the example, when you add the letter o to the b so that the Inc Search field now has bo, the bo in Boston becomes highlighted. • If you mistype in the Inc Search field, use the Back Space key to remove the last letters and make corrections. • After finding the bo, you can press Ctrl+W to complete that word. In this example, Boston appears in the Inc Search field.
3 Running Functions — Command Window and History • When the text is not found, Failing appears in the incremental search field. Modify the search term in the incremental search field and try again. Use Ctrl+G to automatically remove characters back to the last successful search. For example, if plode fails, Ctrl+G removes the de from the search term because plo does exist in the Command Window. 7 To end the incremental search, press Esc or Enter, or any other key that is not a character or number.
Searching in the Command Window In the example, enter bO in the Inc Search field and incremental search does not find any matching text.
3 Running Functions — Command Window and History Preferences for the Command Window In this section...
Preferences for the Command Window Text Display Specify the format, that is, how output appears in the Command Window. Numeric format. Specify the output format of numeric values displayed in the Command Window. This affects only how numbers are displayed, not how MATLAB computes or saves them. The format reference page includes the list of available formats, with examples.
3 Running Functions — Command Window and History Numeric display. Specify spacing of output in the Command Window. To suppress blank lines, use compact. To display blank lines, use loose. For more information, see the reference page for format. Display Wrap lines. Select to make a single line of input or output in the Command Window break into multiple lines in order to fit within the current width of the Command Window. This is useful for console mode.
Preferences for the Command Window This preference setting does not impact the number of lines you can recall when you use the up arrow key in the Command Window. Using the up arrow key, you can recall all lines shown in the Command History window, regardless of how many lines you can see in the Command Window. Accessibility Select this option to use the up and down arrow keys to move the cursor when it is above the command line.
3 Running Functions — Command Window and History • “Command Window Key Bindings” on page 3-44 • “Editor/Debugger Key Bindings” on page 3-45 • “Tab Completion” on page 3-45 • “Tabs and Indents” on page 3-46 • “Delimiter Matching” on page 3-46 Command Window Key Bindings Specify the keyboard shortcuts (key bindings) to be used at the command line.
Preferences for the Command Window MATLAB standard (Emacs). Allows you to use the control keys listed in “Keyboard Shortcuts in the Command Window” on page 3-26, which should be familiar to existing MATLAB users and Emacs users. For example, Ctrl+A moves the cursor to the beginning of the line. Windows. Allows you to use standard Windows control keys. For example, Ctrl+A is the shortcut for Edit > Select All, which selects the entire contents of the Command Window. Macintosh.
3 Running Functions — Command Window and History Enable in Editor/Debugger. Select the check box to use tab completion when typing functions in the Editor/Debugger. Clear the check box if you do not want to use the tab completion feature. In that event, when you press the Tab key, MATLAB moves the cursor to the next tab stop rather than completing a function — see also in the online documentation. Tab key narrows completions.
Preferences for the Command Window If the matching delimiter is not visible on the screen, a pop-up window appears and shows the line containing the matching delimiter. In the Editor/Debugger, the line number is included. Click in the pop-up window to go to that line. Match while typing. Select the check box if you want to be alerted to matches and mismatches in pairs of delimiters as you type them. Then choose how you want MATLAB to alert you to matches by selecting an entry from Show match with.
3 Running Functions — Command Window and History Match on arrow key. Select the check box if you want to be alerted to matches and mismatches in pairs of delimiters when you use an arrow key to move the cursor over a delimiter. Then choose how you want MATLAB to alert you to matches by selecting an entry from Show match with.
Command History Window Command History Window In this section... “Overview” on page 3-49 “Viewing Statements in the Command History Window” on page 3-50 “Using Statements from the Command History Window” on page 3-51 “Searching in the Command History Window” on page 3-52 “Printing the Command History Window” on page 3-57 “Deleting Entries from the Command History Window” on page 3-57 Overview The Command History window displays a log of the statements most recently run in the Command Window.
3 Running Functions — Command Window and History MATLAB provides other options for viewing a history of statements.
Command History Window Using Statements from the Command History Window You can select entries in the Command History window and then perform the following actions for the selected entries. Action How to Perform the Action Run statements in the Command Window Double-click an entry (entries) in the Command History window to execute the statement(s) in the entries. For example, double-click edit myfile to open myfile.m in the Editor/Debugger.
3 Running Functions — Command Window and History Searching in the Command History Window There are two types of search in the Command History window: • “Finding Next Entry By Letter” on page 3-52 • “Finding Text” on page 3-56 After finding an entry, you can copy and paste it into an M-file or any file, or you can right-click and select Evaluate Selection to run the entry. Finding Next Entry By Letter Type a letter in the Command History window.
Command History Window 2 Type the first letters of the entry you want to find. For example, type my. The Command History window searches backwards and selects the previous entry that begins with the letters you typed; in this example, you typed my, and the Command History finds myfor. As you begin typing that a small yellow-background pop-up window, Search history for:, appears at the top of the Command History window.
3 Running Functions — Command Window and History Finding Multiple Occurrences of the Entry. You can use the up and down arrow keys to search for the next or the previous occurrence of the entry you just found. When you press Ctrl and the up or down arrow key, each occurrence of the entry remains highlighted while you search for additional instances.
Command History Window To highlight all instances of the entry, press Ctrl+A. In the example below, all instances of entries beginning with my are highlighted.
3 Running Functions — Command Window and History Finding Text Select Find from the Edit menu to search for specified text using the Find dialog box. Complete the dialog box. The search begins at the current cursor position. MATLAB finds the text you specified and highlights it. Click Find Next or Find Previous to find another occurrence, or use the keyboard shortcuts F3 and Shift+F3. Find looks for visible entries only, that is, it does not find entries in collapsed nodes.
Command History Window MATLAB beeps when a search for Find Next reaches the end of the Command History window, or when a search for Find Previous reaches the top of the Command History window. If you have Wrap around selected, it continues searching after beeping. Change the selection in the Look in field to search for the specified text in other MATLAB desktop tools. Printing the Command History Window To print the contents of the Command History window, select File > Print or Print Selection.
3 Running Functions — Command Window and History To delete entries in the Command History window, first select the entries to delete, using one of these methods: • Select a single entry. • Shift+click or Ctrl+click to select multiple entries. • Select the timestamp for a session to select all entries for that session. Then use Shift+click or Ctrl+click to select multiple timestamps with all of their entries. Then right-click and select Delete selection from the context menu, or press the Delete key.
Preferences for Command History Preferences for Command History In this section... “Introduction” on page 3-59 “Settings” on page 3-59 “Saving” on page 3-60 “See Also” on page 3-60 Introduction Using Command History preferences, you can choose to exclude statements from the history.m file and specify how often to save it. The history.m file is used for both the Command History window and statement recall in the Command Window. To set preferences for the history.
3 Running Functions — Command Window and History one entry for magic(5). If you then run magic(10), the command history file saves both entries, magic(5) followed by magic(10). Saving Use Saving preferences to specify how often to automatically save the history.m file during a MATLAB session. Save History File On Quit Select this option to save the history.m file when you end the MATLAB session.
4 Help for Using MATLAB The primary means for getting help is the Help browser, which provides documentation for all your installed products. Other forms of help are available including M-file help and Technical Support solutions. If you have an active Internet connection, you can watch the Help and Documentation video demo for an overview of the major functionality. Help Browser Overview (p. 4-3) Get information about your MathWorks products using the Help browser.
4 4-2 Help for Using MATLAB Help Functions (p. 4-44) Use functions to get information, such as help and doc. Getting Pop-Up Help for Functions (p. 4-49) Get pop-up help (help on selection) for functions from within the Editor/Debugger and the Command Window. Other Forms of Help (p. 4-51) Use product-specific help features, download M-files, contact Technical Support, see documentation for other MathWorks products, view a list of other books, and participate in a MATLAB newsgroup.
Help Browser Overview Help Browser Overview In this section... “About the Help Browser” on page 4-3 “Opening the Help Browser” on page 4-3 “Resizing the Help Browser” on page 4-5 “Types of Documentation” on page 4-7 “Accessing Documentation on the Web” on page 4-8 “Adding Help Files” on page 4-9 “Documentation in Other Languages” on page 4-9 About the Help Browser The Help browser is an HTML browser integrated with the MATLAB desktop.
4 Help for Using MATLAB Tabs in the Help Navigator pane provide different ways to find information. Use the close box to hide the pane. 4-4 Drag the separator bar to adjust the width of the panes. View documentation in the display pane.
Help Browser Overview Resizing the Help Browser To adjust the relative width of the two panes, drag the separator bar between them. You can also change the font in either of the panes — see “Help Fonts and Colors Preferences” on page 4-39. Once you find the documentation you want, you can close the Help Navigator pane so there is more screen space to view the information itself. This is shown in the following figure. To close the Help Navigator pane, click the Close box in the pane’s upper right corner.
4 4-6 Help for Using MATLAB
Help Browser Overview Types of Documentation The Help browser and help functions provide access to the following types of information for all installed MathWorks products. The icons shown here appear in the Help browser contents listing to help you quickly identify documentation by type. Icon or Type of Documentation Description and When to Use Getting Started Review Getting Started documentation before you begin using a product or feature for the first time.
4 Help for Using MATLAB Icon Type of Documentation Description and When to Use Printable Documentation Most products provide access to the online documentation in a printable format, PDF. Access PDF files via the Help browser and print them from your PDF reader, such as Adobe Acrobat. Most PDF files reside only on the MathWorks Web site, so you need an Internet connection to view them. none Demos MathWorks products come with demonstrations that run key features of the product.
Help Browser Overview • Access documentation via your system Web browser, such as when you are not running MATLAB or if you prefer your system Web browser. To determine the URL for a page in the Help browser, see “View the Page Location” on page 4-30 PDF documentation is available only on the Web site. You cannot read MATLAB documentation files from the MATLAB installation media.
4 Help for Using MATLAB Finding Information with the Help Browser In this section... “Help Navigator” on page 4-10 “Contents in the Help Browser” on page 4-10 “Index for the Help Browser” on page 4-13 “Search Documentation and Demos with the Help Browser” on page 4-16 “Favorites” on page 4-24 Help Navigator The Help Navigator is in the left pane of the Help browser. It provides a table of contents, an index, and a search feature to help you find information.
Finding Information with the Help Browser Product Roadmap When you select a product in the Contents pane (any entry with a book icon ), such as MATLAB or Communications Toolbox, a roadmap of the documentation for that product appears in the display pane.
4 Help for Using MATLAB • Function and block references pages • An index of major examples in the documentation • The PDF version of the documentation, which is suitable for printing (this is the only direct access from MATLAB to the printable documentation) Navigate the Contents Listing In the Contents listing, you can • Click the + to the left of an item to show the first page of that document or section in the display pane and expand the listing for that item in the Help Navigator pane.
Finding Information with the Help Browser only applies to the major headings in a document. For pages that begin with lower level headings, the Contents pane listing does not synchronize. You can turn off synchronization. To do so, use preferences. See “General — Keep Contents Synchronized” on page 4-38. Synchronization applies to the Contents and Demos panes. The page shown in the display pane does not necessarily correspond to the selection in the Index, or Search Results panes.
4 Help for Using MATLAB 1 Click the Index tab. 2 Type a word or words in the Enter index term field. As you type, the Index pane displays matching entries and their subentries (indented). It might take a moment for the display to appear.
Finding Information with the Help Browser sensitive. If there is not a matching entry, it displays the page for the letter that your entry begins with. The product whose documentation includes the matching index entry is listed next to the index entry, which is useful when there are multiple matching index entries. You might have to make the Help Navigator pane wider to see the product.
4 Help for Using MATLAB • For different but related results, try using the Search for field—for instructions, see “Search Documentation and Demos with the Help Browser” on page 4-16. • See “Specifying Colors for the Help Browser” on page 4-41 for information about changing the color of hyperlinks in the Index.
Finding Information with the Help Browser 1 To limit (or extend) the products whose documentation and demos are searched, set the product filter.
4 Help for Using MATLAB 2 In the Search for field, type the word or words you want to find and click Go (or press Enter or Return). Some techniques for honing your search are • Exact Phrase — Search for an exact phrase by enclosing words in quotation marks, for example, "plot tools". For more information, see “Exact Phrases in Search” on page 4-21.
Finding Information with the Help Browser that contain all search words, with pages containing a single instance of each search word appearing last. Change the display of search results to more easily find the most relevant results: • Sort by column — Change the order of the results by clicking a column heading. For example, click Product to group results by product. Click Title to sort titles alphabetically. A triangular icon indicates the column on which you most recently sorted.
4 Help for Using MATLAB Function Alternative. From the Command Window, use docsearch to open the Help browser to the Search pane and search for the specified term. For example docsearch('publish* html') finds all pages that contain the word publish or its variations, such as publishing, published, and so on, and also contains the word html. docsearch('"plot tools"') finds all pages containing the exact phrase plot tools.
Finding Information with the Help Browser For details, see the docsearch reference page. Wildcards in Search (Partial Word) You can use the wildcard character (*) in place of letters or digits in your search terms. For example, plot* finds various forms of the word plot, such as plot, plots, and plotting. The search term p*t also finds those variations of plot as well as variations of print and part, among others. You can use multiple wildcards in a word or search term.
4 Help for Using MATLAB Example Using Boolean Operators in Search. Type plot* tools NOT time series to find all pages that contain the words plot or its variations and tools, but not the phrase time series. More About Search These are the guidelines search uses: • Insignificant words (a, an, the, of) are ignored. • Search is not case sensitive. • Search only finds letters and digits, but not symbols.
Finding Information with the Help Browser Problem Try These Suggestions Pages are not about search word, but just mention it Try the Index pane to see more important entries for that search word. Too many irrelevant results Type more than one word in the Search for field. Look for an exact phrase by enclosing words in quotations marks, such as "plot tools". Use Boolean operators (in all capitals), for example, printing AND figures NOT exporting.
4 Help for Using MATLAB Problem Try These Suggestions No results but you know the word should be there Try variations of the search word by using a wildcard symbol (*). For example, search for preference* to find all pages that contain either the word preference or the word preferences. Not enough information Try searching the Technical Support database of bug reports, solutions, and technical notes by clicking the link at the bottom of the Search results pane.
Finding Information with the Help Browser A favorite is implemented as a MATLAB shortcut, so the dialog box is the same as for the Shortcut Editor. Favorites from previous releases are not migrated to a new release. Go to Favorites Select the Favorites menu to view the list of pages you previously designated as favorites (bookmarks). Select an entry and that page appears in the display pane. Organize Favorites You can rename, remove, and reorder the list of favorites.
4 Help for Using MATLAB Viewing Documentation in the Help Browser In this section...
Viewing Documentation in the Help Browser Browse to Other Pages Use the arrow buttons in the page and in the toolbar to go to other pages.
4 Help for Using MATLAB View the next page in a document by clicking the Next page button at the top or bottom of the page. View the previous page in a document by clicking the Previous page button at the top or bottom of the page. These arrows allow you to move forward or backward within a single document. The arrows at the bottom of the page are labeled with the title of the page they go to. View the page previously shown by clicking the Back button in the display pane toolbar.
Viewing Documentation in the Help Browser You can change the selection in the Look in field to search for the specified text in other MATLAB desktop tools. See “Search Documentation and Demos with the Help Browser” on page 4-16 for instructions on looking through all the documentation instead of just one page. Copy Information To copy information from the display pane, such as code in an example, first select the information. Then right-click and select Copy from the context menu.
4 Help for Using MATLAB them into other tools like the Editor/Debugger or Command Window, or into other applications. View the Page Location To view the location of the page currently displayed, select View > Page Location. The Help Page Location dialog box appears, providing the full path to the documentation file for both your local system and the MathWorks Web site.
Demos in the Help Browser Demos in the Help Browser In this section... “About Demos” on page 4-31 “Using Demos” on page 4-32 “Adding Your Own Demos” on page 4-36 About Demos MATLAB and related products include demos that you can access from the Help browser Demos pane. There are four types of demos: • M-file: Demos that tell a step-by-step story, including source code, commentary, and output. They are published from M-file scripts to HTML output using the Editor/Debugger.
4 Help for Using MATLAB Using Demos To access demos for the products you have installed, 1 Click the Demos tab in the Help Navigator. You can also access demos from the Start button, by using the demo function, or from the Help menu for some tools. 2 Click the + for a product area to list the products or categories that have demos. Then click + for a product or product category to list its demos.
Demos in the Help Browser 4 You can then view and run the demo, with specific options depending on the type of demo: 4-33
4 Help for Using MATLAB • For M-file demos, click the Open filename in the Editor link at the top left. This opens the M-file in the Editor/Debugger. From the Editor/Debugger, run the demo step by step by selecting Cell > Evaluate Current Cell and Advance. You can also click Run in the Command Window, and then follow the instructions that appear in the Command Window. You might need to scroll up to see all of the instructions. See also “Running Demos and Base Workspace Variables” on page 4-35.
Demos in the Help Browser Searching for Demos You can use the Help browser search feature to find demos. Search find words in comments or code for M-file and Model types demos. It finds comments in the M-file help for M-GUI demos. It does not search video demos. For instructions, see “Search Documentation and Demos with the Help Browser” on page 4-16. Running Demos and Base Workspace Variables M-file demos run as scripts. Their variables are created in the MATLAB base workspace.
4 Help for Using MATLAB Function Alternative To open the Demos pane in the Help browser, type demo in the Command Window. You can go directly to the demos for a specific product. For example demo toolbox signal opens the Demos listing for Signal Processing Toolbox. To run an M-GUI demo, type the demo name in the Command Window. For example, type vibes to run the MATLAB Graphics demo showing an animated L-shaped membrane.
Preferences for the Help Browser Preferences for the Help Browser In this section... “Product Filter” on page 4-37 “PDF Reader — Specifying Its Location” on page 4-38 “General — Keep Contents Synchronized” on page 4-38 “Help Fonts and Colors Preferences” on page 4-39 Product Filter If you have MathWorks products in addition to MATLAB, such as Simulink, toolboxes, and blocksets, set the product filter to limit the product documentation and demos used: 1 Select File > Preferences > Help.
4 Help for Using MATLAB Example Using the Product Filter If you want to perform a search and have many products installed but know the information you are seeking is in MATLAB or Communications Toolbox, in the Help Product Filter, click Clear All and then select MATLAB and Communications Toolbox.
Preferences for the Help Browser Help Fonts and Colors Preferences Set fonts and colors for the Help browser the same way you would for other desktop tools. This section describes the process for the Help browser: • “Specifying Font Name, Style, and Size” on page 4-39 • “Specifying Colors for the Help Browser” on page 4-41 Specifying Font Name, Style, and Size You can specify the font name (also called font type or family), style, and size used in the Help Navigator.
4 4-40 Help for Using MATLAB
Preferences for the Help Browser Use the same method as you would to specify fonts for any desktop tool — for more information, see “Fonts Preferences for Desktop Tools” on page 2-62. By default, the Help Navigator uses the desktop text font. The display pane is considered to be an HTML Proportional Text tool, and by default, uses the desktop text font. This example changes the display pane font: 1 Select File > Preferences > Fonts > Custom. 2 From the Desktop tools list, select HTML Proportional Text.
4 Help for Using MATLAB Printed Documentation In this section... “About Printed Manuals” on page 4-42 “Printing a Page from the Help Browser” on page 4-42 “Printing the PDF Version of Documentation” on page 4-42 About Printed Manuals Generally, printed manuals are not provided for most products and tools. The printed manuals typically contain less information, and is also sometimes less current than the online documentation.
Printed Documentation Note The Help browser accesses PDF documentation from the MathWorks Web site. Therefore, you need Internet access to view or print PDF documentation. 1 In the Help browser, click the Contents tab and select a product, for example, MATLAB. The roadmap page opens for that product, providing links to key documentation for that product. 2 Near the end of the roadmap page, listed under Printing the Documentation Set, are links for printing the documentation.
4 Help for Using MATLAB Help Functions In this section... “About Help Functions” on page 4-44 “Summary Table of Help Functions” on page 4-44 “View Function Reference Pages — the doc Function” on page 4-45 “Getting Help in the Command Window — the help Function” on page 4-46 About Help Functions There are several help functions that provide forms of help different than the Help browser documentation, or provide alternative ways to access the Help browser information.
Help Functions Function Description helpbrowser Opens the Help browser, the MATLAB interface for accessing documentation. helpdesk Opens the Help browser. In previous releases, helpdesk displayed the Help Desk, which was the precursor to the Help browser. This function will be removed in a future release. helpwin Displays in the Help browser a list of all functions, and provides access to M-file help for the functions.
4 Help for Using MATLAB database/set which is the set function for Database Toolbox. Click a link to go to that set reference page. To directly get the reference page for an overloaded function, specify the name of the directory containing the function you want the reference page for, followed by the function name. For example, to display the reference page for the set function in Database Toolbox, type doc database/set Some products have more than one function with the same name.
Help Functions Note M-file help displayed in the Command Window uses all uppercase characters for the function and variable names to distinguish them from the rest of the text. When typing function names, however, use lowercase characters. Some functions for interfacing to Java do use mixed case; the M-file help accurately reflects that, and you should use mixed case when typing them.
4 Help for Using MATLAB help database/set Creating M-File Help for Your Own M-Files You can create M-file help for your own M-files and access it using the help command. See the help reference page for details. Help in the Current Directory Browser The Help Report and the Contents Report provide other ways of looking at and managing help for M-files — see “Directory Reports in Current Directory Browser” on page 7-2.
Getting Pop-Up Help for Functions Getting Pop-Up Help for Functions MATLAB provides pop-up help for MATLAB functions from both the Editor/Debugger and the Command Window. Pop-up help, also referred to as “help on selection,” enables you to view documentation for a function without requiring you to interrupt the flow of your work to open the Help browser. To access pop-up help, follow these steps: 1 Select a function or click the pointer in a function for which you want information.
4 4-50 Help for Using MATLAB
Other Forms of Help Other Forms of Help In this section...
4 Help for Using MATLAB who downloads them. To view the files available to download, go to the MATLAB Central File Exchange page on the MathWorks Web site, http://www.mathworks.com/matlabcentral/fileexchange/index.jsp. You can access this from any desktop component via Help > Web Resources. If you write M-files that you think would be of use to others, consider submitting them to the MATLAB Central File Exchange via the Web page.
Other Forms of Help First-time users to the newsgroup should read the newsgroup FAQ, linked to from the MATLAB Central page. It is a good practice to try to solve your own problem using the documentation and Technical Support database before posting a question to the newsgroup. Be sure to post with a meaningful subject that briefly describes the nature of the issue.
4 Help for Using MATLAB Provide Feedback To report problems or provide comments or suggestions to The MathWorks about the documentation, help features, or products, use the Provide feedback on this page link on the top and bottom of every page in the Help browser.
5 Workspace, Search Path, and File Operations If you have an active Internet connection, you can watch the Workspace Browser video demo, the Array Editor video demo, and the Current Directory Browser video demo for an overview of the major functionality. MATLAB Workspace (p. 5-2) The workspace is the set of variables maintained in memory during a MATLAB session. Use the Workspace browser or equivalent functions to view the workspace. Viewing and Editing Workspace Variables with the Array Editor (p.
5 Workspace, Search Path, and File Operations MATLAB Workspace In this section...
MATLAB Workspace Opening the Workspace Browser To open the Workspace browser, select Workspace from the Desktop menu in the MATLAB desktop, or type workspace at the Command Window prompt. The Workspace browser opens. Viewing and Editing Values in the Current Workspace The Workspace browser shows the name of each variable, its value, and the Min and Max calculations, which MATLAB computes using the min and max functions, and updates automatically. The icon for each variable denotes its class.
5 Workspace, Search Path, and File Operations • You can select the column on which to sort as well as reverse the sort order of any column. Click a column heading to sort on that column. Click the column heading again to reverse the sort order in that column. For example, to sort on Name, click the column heading once. To change from ascending to descending, click the heading again. You cannot sort by the Value column in the Workspace browser.
MATLAB Workspace Your variables are: A C M R >> whos Name A C M R S c S c Size Bytes 4x4 1x3 4x4x24 3x4x5 1x3 1x16 128 348 3072 480 826 32 Class Attributes double cell double double struct char Use exist to see if the specified variable is in the workspace. Saving the Current Workspace The workspace is not maintained across MATLAB sessions. When you quit MATLAB, the workspace is cleared.
5 Workspace, Search Path, and File Operations The workspace variables are saved under the MAT-file name you specified. You can also save the workspace variables from the desktop by selecting Save Workspace As from the File menu. Saving Selected Variables To save some but not all of the current workspace variables, 1 Select the variable in the Workspace browser. To select multiple variables, Shift+click or Ctrl+click. 2 Right-click and from the context menu, select Save As.
MATLAB Workspace information — see “Data Import and Export” in the MATLAB Programming documentation. Loading a Saved Workspace and Importing Data To load saved variables into the workspace, 1 Click the Import Data button on the toolbar in the Workspace browser. The Open dialog box opens. 2 Select the MAT-file you want to load and click Open. The variables and their values, as stored in the MAT-file, are loaded into the current workspace.
5 Workspace, Search Path, and File Operations Function Alternative. Use whos with the -file option. Changing and Copying Variable Names To rename a variable in the workspace, right-click the variable in the Workspace browser and select Rename from the context menu. Type the new variable name over the existing name and press Enter or Return. To copy variable names to the clipboard, select the workspace variables and select Edit > Copy. You can then paste the names, for example, into the Command Window.
MATLAB Workspace Viewing Base and Function Workspaces Using the Stack When you run M-files, MATLAB assigns each function its own workspace, called the function workspace, which is separate from the MATLAB base workspace. To access the base and function workspaces when running or debugging M-files, use the Stack field in the Workspace browser. The Stack field is only available in debug mode and otherwise is grayed out. The Stack field is also accessible from the Array Editor and the Editor/Debugger.
5 Workspace, Search Path, and File Operations Some toolboxes allow you to double-click an object in the Workspace browser to open a viewer or other tool appropriate for that object. For details, see the toolbox documentation for that object type. Preferences for the Workspace Browser The Workspace browser displays statistical calculations for variables. Use preferences to restrict the size of arrays on which calculations are performed and to specify if NaNs are included or ignored in calculations.
MATLAB Workspace Specify Maximum Array Size on Which to Compute Statistics If you show statistical columns in the Workspace browser, and if you work with very large arrays, you might experience performance issues when the data changes as MATLAB updates the statistical results. In that event, show only the columns of interest to you and hide those you do not need. Another step you can take is specify via a preference that the Workspace browser not perform statistical calculations on the largest arrays.
5 Workspace, Search Path, and File Operations Viewing and Editing Workspace Variables with the Array Editor In this section...
Viewing and Editing Workspace Variables with the Array Editor 1 In the Workspace browser, select the variable you want to open. Shift+click or Ctrl+click to select multiple variables, or use Ctrl+A to select all variables to open. 2 Click the Open Selection button on the toolbar. For one variable, you can also open it by double-clicking it. The Array Editor opens, displaying the values for the selected variable. Repeat the steps to open additional variables in the Array Editor.
5 Workspace, Search Path, and File Operations Note The maximum array size that you can open in the Array Editor is not limited by MATLAB, but is based on your operating system or the amount of physical memory installed on your system. Function Alternatives To open a variable in the Array Editor, use openvar with the name of the variable you want to open as the argument. For example, type openvar('M') MATLAB opens M in the Array Editor.
Viewing and Editing Workspace Variables with the Array Editor Similarly, double-click a cell in a cell array to view and edit its contents. The following illustration shows an 8-by-1 cell array, M, and the contents of M{4,1}. Multidimensional Arrays in the Array Editor You can view the contents of multidimensional arrays in the Array Editor. When you open a multidimensional array in the Array Editor, it does not have usual grid structure, because multidimensional arrays do not fit that format.
5 Workspace, Search Path, and File Operations Navigating and Editing Shortcut Keys for the Array Editor Use the following shortcut keys (sometimes called hot keys) to move among elements in the Array Editor. Navigating in the Array Editor is much like navigating in Microsoft Excel.
Viewing and Editing Workspace Variables with the Array Editor Key Result Tab Move right Within a selection, also moves from the last column to the first column in the next row Shift+Enter or Shift+Tab Move in opposite direction of Enter or Tab Page Up Move up m rows, where m is the number of visible rows Page Down Move down m rows, where m is the number of visible rows Home Move to column 1 Ctrl+Home Move to row 1, column 1 Shift+Home Select to column 1 End Move to last column in current r
5 Workspace, Search Path, and File Operations the Preferences dialog. For more information, see “Preferences for the Array Editor” on page 5-22. If you opened an existing MAT-file and made changes to it using the Array Editor, save that MAT-file if you want the changes to be saved. For instructions, see “Saving the Current Workspace” on page 5-5.
Viewing and Editing Workspace Variables with the Array Editor Example Copying and Pasting Array Elements In this example, two elements are copied but the selected area for pasting is only one element, so the Array Editor expands the selected area for pasting.
5 Workspace, Search Path, and File Operations Example Cutting and Pasting Array Elements In this example, the area selected for pasting requires the Array Editor to expand the array size in order for all cut elements to be pasted.
Viewing and Editing Workspace Variables with the Array Editor Insert and Delete in the Array Editor You can insert and delete elements, rows, and columns in the Array Editor. When you select Edit > Insert, or Edit > Delete, a dialog box appears in which you specify cells, rows, or columns, and for cells, the direction for shifting. Undo and Redo in the Array Editor You can undo the last action you performed in the Array Editor, or redo a change after choosing undo. Select Edit > Undo or Edit > Redo.
5 Workspace, Search Path, and File Operations To create a new variable, select a cell, row, or column in the Array Editor, right-click, and from the context menu, select Create Variable from Selection. Preferences for the Array Editor To set preferences for the Array Editor, select File > Preferences. The Preferences dialog box opens showing Array Editor Preferences. Format Specify the default array output format of numeric values displayed in the Array Editor.
Search Path Search Path In this section... “About the Search Path” on page 5-23 “How the Search Path Determines Which Function to Use” on page 5-24 “How MATLAB Finds the Search Path, pathdef.
5 Workspace, Search Path, and File Operations action so that MATLAB runs the file you want—for more information, see “How the Search Path Determines Which Function to Use” on page 5-24. The search path is also referred to as the MATLAB path. Directories included are considered to be on the path. When you include a directory in the search path, you add it to the path. Subdirectories must be explicitly added to the path; they are not on the path just because their parent directories are.
Search Path • If you are not sure of the function MATLAB is using, run which for a specified function and MATLAB returns the full path to the function. Although the actual search path rules are more complicated because of the restricted scope of private functions, subfunctions, object-oriented functions, P-files, and MAT-files, this simplified perspective is accurate for the ordinary M-files you usually work with.
5 Workspace, Search Path, and File Operations Viewing and Setting the Search Path Use the Set Path dialog box to view and modify the MATLAB search path. Equivalent functions are documented for each feature of the Set Path dialog box. Select Set Path from the File menu, or type pathtool at the Command Window prompt. The Set Path dialog box opens. Use the Set Path dialog box for the following actions.
Search Path • “Viewing the Search Path” on page 5-27 • “Adding Directories to the Search Path” on page 5-27 • “Moving Directories Within the Search Path” on page 5-28 • “Removing Directories from the Search Path” on page 5-29 • “Restoring the Default Search Path” on page 5-30 • “Reverting to the Previous Path” on page 5-30 • “Saving Settings to the Path” on page 5-30 See also • “About the Search Path” on page 5-23 • “Using the Path in Future Sessions” on page 5-31 • “Recovering from Problems with the Searc
5 Workspace, Search Path, and File Operations The Browse for Folder dialog box opens. 2 In the Browse for Folder dialog box, use the view of your file system to select the directory to add, and then click OK. The selected directory, and subdirectories if specified in step 1, are added to the top of the search path. 3 To use the newly modified search path in future sessions, click Save. For more information about saving the path, see “Saving Settings to the Path” on page 5-30. 4 Click Close.
Search Path 2 Click one of the Move buttons, such as Move to Top. The order of the directories changes. 3 To use the newly modified search path in future sessions, click Save. For more information about saving the path, see “Saving Settings to the Path” on page 5-30. 4 Click Close. If you did not save the changes in the previous step, the new order of files on the search path remains in effect until you end the current MATLAB session. Function Alternative.
5 Workspace, Search Path, and File Operations Restoring the Default Search Path To restore the default search path, click Default in the Set Path dialog box. This changes the search path so that it includes only the directories installed with MATLAB and related products. Reverting to the Previous Path To restore the previous path, click Revert in the Set Path dialog box. This cancels any unsaved changes you have made in the Set Path dialog box.
Search Path Caution Against Saving Files in matlabroot/toolbox. Save any M-files you create and any MathWorks supplied M-files that you edit in a directory that is not in the matlabroot/toolbox directory tree. If you keep your files in matlabroot/toolbox directories, they can be overwritten when you install a new version of MATLAB. Also note that locations of files in the matlabroot/toolbox directory tree are loaded and cached in memory at the beginning of each MATLAB session to improve performance.
5 Workspace, Search Path, and File Operations By maintaining an unaltered pathdef.m in matlabroot/toolbox/local, you avoid inadvertently removing directories supplied by The MathWorks from the path. This method continues working even when you update to a new version of MATLAB. If you run MATLAB on both Windows and UNIX platforms, this method works well — for example, for each platform, include separate addpath sections in the startup.m file, with each section preceded by an ispc or isunix statement.
Search Path Recovering from Problems with the Search Path If you get unexpected results that are related to the search path, you can try to correct the path file or restore the default path. You might experience path problems if you save the path on a Windows platform and then try to use the same pathdef.m file on a UNIX platform. Similarly, you might experience problems if you edit the pathdef.m file directly and make it invalid, or if the file becomes corrupt, renamed, or lost.
5 Workspace, Search Path, and File Operations a Run restoredefaultpath; matlabrc This might run for a few minutes. It sets the search path to include only installed products from The MathWorks and corrects path problems encountered during startup. b If there is a pathdef.m in your startup directory for MATLAB, it caused the problem. So either remove the bad pathdef.m file or replace the with a good pathdef.
File Management Operations File Management Operations In this section...
5 Workspace, Search Path, and File Operations To change the current directory from this field, do one of the following: • In the field, type the path for the new current directory. • Click the down arrow to view a list of previous working directories, and select an item from the list to make that directory become the MATLAB current working directory. The directories are listed in order, with the most recently used at the top of the list.
File Management Operations The main tasks you perform with the Current Directory browser are • “Viewing and Making Changes to Directories” on page 5-38 • “Creating, Renaming, Copying, and Removing Directories and Files” on page 5-43 • “Opening and Running Files” on page 5-47 • “Finding Files and Content Within Files” on page 5-49 • “Accessing Source Control Features” on page 5-54 • Setting “Preferences for the Current Directory Browser” on page 5-54 5-37
5 Workspace, Search Path, and File Operations Viewing and Making Changes to Directories You can change the current directory, view its contents, add directories to the MATLAB search path, and change the way the Current Directory browser presents entries.
File Management Operations 1 Set C:\Climate as your current directory. 2 Assume that you want to search the Current Directory for the file named standard.m. Begin your search by positioning the cursor anywhere within the Current Directory browser. 3 Type the letter s. The Current Directory browser searches to find the first entry beginning with the letter s. In this example it stops at the directory named standalone.
5 Workspace, Search Path, and File Operations 4 Since the standalone directory is not your intended search target, continue typing additional letters that identify your search target, eventually entering the letters standar. 5 When you have entered the letters standar, the search resumes, stopping this time at the standard.m file, your intended search target.
File Management Operations Changing the Display Types of Files. To specify the types of files shown in the Current Directory browser, use the View menu. For example, you can show only M-files. If All Files is selected and you want to see specific file types, first clear the selection for All Files and then select the specific file types. Columns. To show or hide columns, use preferences for the Current Directory browser.
5 Workspace, Search Path, and File Operations Contents. In the Current Directory browser, select a file and then view information about the file in the Current Directory browser’s lower pane. To view this, you must first select File > Preferences > Current Directory and under Browser display options, select the check box Show M, MDL and MAT file contents. For an M-file, it shows the M-file help.
File Management Operations Adding Directories to the MATLAB Search Path From the Current Directory browser, you can add directories to the MATLAB search path. Right-click and from the context menu, select Add to Path. Then select one of the options: • Current Directory — Adds the current directory to the path. • Selected Folders — Adds the directories selected in the Current Directory browser to the path.
5 Workspace, Search Path, and File Operations generates a warning and does not delete my file.m. Instead use the function form of the syntax: delete('my file.m') Creating New Files To create a new file in the current directory, 1 Select New from the context menu or File menu and then select the type of file to create. An icon for that file type, for example, an M-file icon , with the default name Untitledn, appears at the end of the list of files shown in the Current Directory browser.
File Management Operations 3 Press the Enter or Return key. The directory is added. Function Alternative. To create a directory, use the mkdir function. For example, mkdir newdir creates the directory newdir within the current directory. Renaming Files and Directories To rename a file or directory, select the item, right-click, and select Rename from the context menu. Type over the existing name with the new name for the file or directory, and press Enter or Return. The file or directory is renamed.
5 Workspace, Search Path, and File Operations the Recycle Bin, select Properties from the context menu, and then, under the Global tab, select the check box to Display delete confirmation dialog. Function Alternative. To delete a file, use the delete function. For example, delete('d:/mymfiles/testfun.m') deletes the file testfun.m. You can recover deleted files if you use the recycle function or the equivalent preference described in “Default Behavior of the Delete Function” on page 2-78.
File Management Operations Opening and Running Files • “Opening Files” on page 5-47 • “Running M-Files” on page 5-49 Opening Files You can open a file from the Current Directory browser and the file opens in the tool associated with that file type. To open a file, select one or more files and perform one of the following actions: • Press the Enter or Return key. • Right-click and select Open from the context menu. • Double-click the file(s).
5 Workspace, Search Path, and File Operations You can also import data from a file. Select the file, right-click, and select Import Data from the context menu. The Import Wizard opens. See the Import Wizard documentation for instructions to import the data. You can run a Windows shortcut directly from the Current Directory browser. Double-click the shortcut icon in the Current Directory browser to perform the Windows operation. Function Alternative.
File Management Operations File Type Extension Action Variable none Opens the numeric or string array name in the Array Editor; open calls openvar. Other custom Opens name.custom by calling the helper function opencustom, where opencustom is a user-defined function. Use winopen to open a file using an external application on Windows platforms. To view the content of an ASCII file, such as an M-file, use the type function. For example type('startup') displays the contents of the file startup.
5 Workspace, Search Path, and File Operations To search for files in one or more directories, or to search for specified text in files, follow these instructions: 1 Open the Find Files tool by clicking the Find Files button in the Current Directory browser toolbar, or by selecting Edit > Find Files from any desktop tool, such as the Current Directory browser or the Editor/Debugger. The Find Files dialog box opens.
File Management Operations • To search for text within files, type the text in the Find files containing text field. For example, search for plot. Alternatively, you can select text in the Command Window or Editor/Debugger and that text appears in the Find files containing text field. Under More options, use the Search type to specify Matches whole word, or specify a partial match by selecting Contains text. • To search for text in specified filenames only, type entries in both fields.
5 Workspace, Search Path, and File Operations 7 Click a column heading to sort the results based on that column. Click the column heading again to reverse the sort order for that column. For example, click Line to sort results by line number.
File Management Operations 4 Find Files will not look in any file type in the list whose State check box is selected. It will look in any file type in the list whose State check box is cleared. a Clear or select the State check box as needed to instruct Find Files about file types to skip. b If you want Find Files to skip a file type not shown in the list, enter the file extension in the field at the top of the dialog box and click Add. The type appears in the list.
5 Workspace, Search Path, and File Operations 5 Click OK to accept the changes and close the Edit Skipped File Extensions dialog box. 6 When you click Find in the Find Files tool, the search ignores the selected file types. Function Alternative Use lookfor to search for the specified text in the first line of help for all M-files on the search path. Comparing Files The MATLAB File Comparison tool highlights the line-by-line differences between two files.
File Management Operations History The drop-down list in the current directory field shows the history of current directories, that is, the most recently used current directories. Saving Directories. When the MATLAB session ends, the list of directories will be maintained. Use the Save most recent directories field to specify how many directories will appear on the list at the start of the next MATLAB session. Removing Directories. To remove all entries in the list, click Clear History.
5 Workspace, Search Path, and File Operations • File type • File size • Last modified date • M-file descriptions (the first comment line in the M-file, also called the H1 line) and the start of MDL file descriptions (approximately the first 128 characters) • M-file help, MDL complete descriptions, and MAT-file contents For more information, see “Changing the Display” on page 5-41. Auto-Refresh By default, the Auto-refresh directory view check box is selected, with an update time of 2 seconds.
6 Editing and Debugging M-Files MATLAB provides powerful tools for creating, editing, and debugging files, as detailed here. For information about the MATLAB language and writing M-files, see the MATLAB Programming documentation. Begin with Existing Code (p. 6-3) Use code resources such as your Command Window and History, and existing M-files, demos, and examples. Ways to Edit, Evaluate, and Debug M-Files (p. 6-5) Use the Editor/Debugger in MATLAB for M-files or any text file.
6 6-2 Editing and Debugging M-Files Navigating in an M-File (p. 6-42) Go to a line number, function, bookmark, back and forward, and open a selection. Finding Text in Files (p. 6-49) Find and replace text in the current file or multiple files. Incremental search tool. Comparing Files — File Comparison Tool (p. 6-54) View differences between two files. Keyboard Shortcuts in the Editor/Debugger (p. 6-59) Use the keyboard to navigate in or perform other common actions in a file.
Begin with Existing Code Begin with Existing Code In this section... “Create M-Files from Command Window and History” on page 6-3 “Use Existing M-Files and Examples” on page 6-3 Create M-Files from Command Window and History Before you begin writing MATLAB code in a blank file, consider starting with existing resources for the code, and then use the MATLAB Editor/Debugger to modify the code.
6 Editing and Debugging M-Files Demos and Examples MATLAB and its toolboxes include demonstration programs. You can view the code in the demos and copy it for use in your own M-files. To see the demos, type demo, which opens the Help browser to the Demos pane. For more information about demos, see “Demos in the Help Browser” on page 4-31. There are also code examples in the online documentation. To see a list of examples for a product, type helpbrowser to open the Help browser.
Ways to Edit, Evaluate, and Debug M-Files Ways to Edit, Evaluate, and Debug M-Files There are several methods for creating, editing, evaluating, and debugging files with MATLAB. Creating and Editing Files — Options MATLAB Editor/Debugger Instructions See “Starting, Customizing, and Closing the Editor/Debugger” on page 6-7, and “Saving, Printing, and Closing Files in the Editor/Debugger” on page 6-62.
6 Editing and Debugging M-Files Use preferences for the Editor/Debugger to set up the editing and debugging environment to best meet your needs. For information about the MATLAB language and writing M-files, see the MATLAB Programming documentation.
Starting, Customizing, and Closing the Editor/Debugger Starting, Customizing, and Closing the Editor/Debugger In this section...
6 Editing and Debugging M-Files Creating a New File in the Editor/Debugger To create a new text file in the Editor/Debugger, either click the New M-file button on the MATLAB desktop toolbar, or select File > New > M-File from the MATLAB desktop. The Editor/Debugger opens, if it is not already open, with an untitled file in the MATLAB current directory, in which you can create an M-file or another type of text file.
Starting, Customizing, and Closing the Editor/Debugger Function Alternative Type edit in the Command Window to create a new file in the Editor/Debugger. Type edit filename.ext to create the file filename.ext. If filename.ext already exists in the current directory or on the MATLAB search path, this opens the existing file. If filename.ext does not exist in the current directory or on the MATLAB search path, a confirmation dialog box might appear asking if you want to create a new file titled filename.
6 Editing and Debugging M-Files To make a document in the Editor/Debugger become the current document, click it, or select it from the Window menu or document bar. M-File Cells If you open an M-file that contains M-file cells, yellow highlighting and gray horizontal lines might appear in the M-file, along with an information toolbar. Cell mode is used for publishing results and rapid code iteration. An M-file cell is denoted by a %% at the start of a line.
Starting, Customizing, and Closing the Editor/Debugger File > Preferences > Editor/Debugger and in the Most recently used file list, specify the Number of entries. • In the Editor/Debugger or another desktop tool such as the Command Window, select a filename, right-click, and select Open Selection from the context menu to open that file. For details, see “Opening a Selection in an M-File” on page 6-48.
6 Editing and Debugging M-Files Click the + next to Editor/Debugger in the left pane to view all categories of Editor/Debugger preferences. Select a category and that preference pane displays. Make changes and click Apply or OK. Click the Help button in the Preferences dialog box for details about Editor/Debugger preferences. Creating and Editing Other Text File Types You can edit any type of text file using the MATLAB Editor/Debugger. For example, you can open and edit an HTML file.
Starting, Customizing, and Closing the Editor/Debugger When working with files created for C/C++, Java, and HTML, you can specify syntax highlighting and indenting preferences appropriate to those languages. Select File > Preferences > Editor/Debugger > Language. See details in the online documentation for Editor/Debugger language preferences, or click the Help button in the dialog box. Closing the Editor/Debugger To close the Editor/Debugger, click the Close box in the title bar of the Editor/Debugger.
6 Editing and Debugging M-Files Entering Statements in the Editor/Debugger In this section... “Use Command Window Features in the Editor/Debugger” on page 6-14 “Changing the Case of Selected Text” on page 6-14 “Undo and Redo” on page 6-15 “Adding Comments” on page 6-15 “Tab Completion in the Editor/Debugger” on page 6-21 Use Command Window Features in the Editor/Debugger After opening an existing file or creating a new file in the Editor/Debugger, enter statements in the file.
Entering Statements in the Editor/Debugger • Reverse Case to change the case of each letter This is useful, for example, when copying syntax from help in an M-file, where function and variable names are distinguished by the use of uppercase. But because of that, the code will not run in MATLAB. In this example, the text was copied and pasted from the output of help get. V = GET(H, 'Default') Select all of the text. Select Text > Change to Lower Case.
6 Editing and Debugging M-Files • “Commenting in Java and C/C++ Files Using the MATLAB Editor/Debugger” on page 6-17 • “Commenting in M-File Using Any Text Editor” on page 6-17 • “Commenting Out Part of a Statement” on page 6-19 • “Formatting Comments in M-Files” on page 6-20 Commenting in M-Files Using the MATLAB Editor/Debugger You can comment the current line or a selection of lines in an M-file: 1 For a single line, position the cursor in that line.
Entering Statements in the Editor/Debugger Commenting in Java and C/C++ Files Using the MATLAB Editor/Debugger For Java and C/C++ files, selecting Text > Comment adds the // symbols at the front of the selected lines. Similarly, Text > Uncomment removes the // symbols from the front of selected lines in Java and C/C++ files. Commenting in M-File Using Any Text Editor You can make any line in an M-file a comment by typing % at the beginning of the line.
6 Editing and Debugging M-Files To comment a contiguous group of lines, type %{ before the first line and %} after the last line you want to comment. This is referred to as a block comment. The lines that contain %{ and %} can contain spaces, but not contain any other text. After typing the opening block comment symbol, %{, all subsequent lines assume the syntax highlighting color for comments until you type the closing block comment symbol, %}.
Entering Statements in the Editor/Debugger Commenting Out Part of a Statement To comment out the end of a statement in an M-file, put the comment character, %, before the comment. When you run the file, MATLAB ignores any text on the line after the %. To comment out text within a multiline statement, use the ellipsis (...). MATLAB ignores any text appearing after the ... on a line and continues processing on the next line.
6 Editing and Debugging M-Files Note that Middle Initial is green, which is the syntax highlighting color for a comment. MATLAB continues processing the statement with the next line MATLAB effectively runs Formatting Comments in M-Files To make comment lines in M-files wrap when they reach a certain column, 1 Specify the maximum column number using preferences for the Editor/Debugger. Select Language > M. For Comment formatting, set the Max width.
Entering Statements in the Editor/Debugger as you reach the 75th column, the comment automatically continues on the next line. Tab Completion in the Editor/Debugger The Editor/Debugger helps you automatically complete the names of these items as you type them in an M-file: • Functions or models on the search path or in the current directory • Variables, including structures, in the current workspace, where the current workspace is shown in the Stack on the toolbar.
6 Editing and Debugging M-Files • “Tab Completion for Structures” on page 6-25 • “Tab Completion for Properties” on page 6-26 • “Using Tab for Spacing” on page 6-27 Basic Example — Unique Completion This example illustrates a basic use for tab completion in the Editor/Debugger. In an M-file opened in the Editor/Debugger, type the beginning of a function or model on the MATLAB search path or in the current directory, for example, horz and press Tab.
Entering Statements in the Editor/Debugger Multiple Possible Completions If there is more than one name that starts with the characters you typed, when you press the Tab key, the Editor/Debugger displays a list of all names that start with those characters. For example, assume you had created the variable costs_march in the base workspace. In an M-file in the Editor/Debugger, type cos and press Tab.
6 Editing and Debugging M-Files You can navigate the list of possible completions using up and down arrow keys, and Page Up and Page Down keys. You can clear the list without selecting anything by pressing Esc. The list of possible completions might include items that are not valid commands, such as private functions. Narrowing Completions Shown You can narrow the list of completions shown by typing a character and then pressing Tab if the Keyboard preference Tab key narrows completions is selected.
Entering Statements in the Editor/Debugger Continue narrowing the list in the same way. For the above example, type o and press Tab to further narrow the list. Press Enter or Return to select an item, which completes the name at the prompt. Tab Completion for Structures For structures that are in the current workspace, after the period separator, press Tab. For example, type mystruct. and press Tab to display all fields of mystruct.
6 Editing and Debugging M-Files Tab Completion for Properties Complete property names for figures in the current workspace using tab completion, as in this graphics example. Here, f is a figure. Type set(f, 'pap and press Tab. The Editor/Debugger displays Select a property from the list. For example, type u and press Enter. The Editor/Debugger completes the property, including the closing quote.
Entering Statements in the Editor/Debugger Using Tab for Spacing If the preference for tab completion is selected, and you want to also use the Tab key to add spacing within your statements, add a space before pressing Tab. For example, to create this statement if a=mate %test input value add a space after mate and then press Tab.
6 Editing and Debugging M-Files Appearance of an M-File — Making Files More Readable In this section...
Appearance of an M-File — Making Files More Readable Indenting Automatic Indenting You can set an indenting preference so that program control entries are automatically indented to make reading loops, such as while/end statements, easier. To do so, select File > Preferences > Editor/Debugger > Language, and select a Language, for example, M. For Indenting for Enter key, select Smart indenting or Block indent, and then click OK. Use No indent instead if you want to indent manually.
6 Editing and Debugging M-Files (a function within a function) in the Editor/Debugger. For details, see in the online documentation. Line and Column Numbers Line numbers are displayed along the left side of the Editor/Debugger window. You can elect not to show the line numbers using preferences — for details, see in the online documentation. The line and column numbers for the current cursor position are shown in the far right side of the status bar in the Editor/Debugger.
Appearance of an M-File — Making Files More Readable Right-Hand Text Limit By default, a light red vertical line (rule) appears at column 75 in the Editor/Debugger, providing a cue as to when a line becomes wider than desired, which is useful if you plan to print the file, for example. You can hide the line or change the column number at which it appears — see in the online documentation.
6 Editing and Debugging M-Files Code folding is particularly useful for improving readability when an M-file contains numerous subfunctions and you want to hide code on which you are not currently working. When you fold a function, all the code associated with that function (including any help code) is collapsed such that the Editor/Debugger displays only the function definition line. The function definition line is appended with an ellipsis icon to indicate there is more function code.
Appearance of an M-File — Making Files More Readable 6-33
6 Editing and Debugging M-Files When you expand a function, but collapse its associated help code, the Editor/Debugger displays all the function code and just the H1 line of the help code.
Appearance of an M-File — Making Files More Readable 6-35
6 Editing and Debugging M-Files To expand code for a construct that is currently collapsed, do one of the following: • Click the plus sign icon expand. to the left of the construct that you want to • Place your cursor in the code that you want to expand, right-click, and then select Code Folding > Expand from the context menu. To collapse code for a construct that is currently expanded, do one of the following: • Click the minus sign icon collapse.
Appearance of an M-File — Making Files More Readable 6-37
6 Editing and Debugging M-Files Code Folding Behavior and Preferences Be aware of the following: • You can change the current code folding settings, by selecting File > Preferences > Editor/Debugger > Code Folding and then clicking Help for assistance. • By default, the first time you open an existing M-file in MATLAB release 7.5 (R2007b), code folding is enabled and all constructs are expanded. • Constructs that are collapsed when you close an M-file remain collapsed when you reopen the file.
Appearance of an M-File — Making Files More Readable 6-39
6 Editing and Debugging M-Files Adjust the size of the views by dragging the splitter. The pointer assumes an arrow shape when it is positioned on the splitter. Only one view is active at any time, meaning, you will only see the cursor in one of the views. To change the active view use Window > Split Screen > Switch Focus or its keyboard equivalent, which is shown with the menu item. The cursor returns to its last position in that view. Make changes to the document in either view.
Appearance of an M-File — Making Files More Readable • Drag the splitter to an edge of the window. • Double-click the splitter. • Select Window > Split > Screen > Off. See also “Summary of Actions for Arranging Documents” on page 2-11 for instructions to display multiple documents simultaneously.
6 Editing and Debugging M-Files Navigating in an M-File In this section... “Going to a Line Number” on page 6-42 “Going to a Function (Subfunctions and Nested Functions)” on page 6-42 “Going to a Bookmark” on page 6-43 “Navigating Back and Forward in Files” on page 6-44 “Opening a Selection in an M-File” on page 6-48 Note See also “Finding Text in Files” on page 6-49. Going to a Line Number Select Go > Go To.
Navigating in an M-File Functions in the list appear alphabetically by name. To order them by their position in the file, click the Line column heading. The list does not include functions that are called from the M-file, but only shows lines in the current M-file that begin with a function statement. on the toolbar. Then select Alternatively, click the Show Functions button the subfunction or nested function you want to go to from the list. The functions are listed in order of position in the file.
6 Editing and Debugging M-Files To set a bookmark, position the cursor anywhere in the line and select Go > Set/Clear Bookmark. A bookmark icon appears to the left of the line. To go to a bookmark, select Next Bookmark or Previous Bookmark from the Go menu. To clear a bookmark, position the cursor anywhere in the line and select Go > Select/Clear Bookmark. Bookmarks are not maintained after you close a file.
Navigating in an M-File For example, if you open a file and make changes at lines 3, 9, and 6, use Go > Back to return to line 9, then 3, then 1, and then use Go > Forward to go from 1 to 3 to 9 to 6, and then return to 3. Detailed instructions to accomplish this are 1 Select Go > Back to return from line 6 to line 9. 2 Select Go > Back again to return to line 3. 3 Select Go > Back again to return to line 1, which is the first line you originally navigate to in a file by virtue of opening it.
6 Editing and Debugging M-Files Lines Navigated to Using Go Back Use Go > Back and Forward to go to lines you previously edited or navigated to via these features: Feature Examples Notes Opening a file (first line in the file) File > Open None Changes made using text-editing tools Delete key, or Text > Increase Indent Edits made to a selection of lines are represented by the first line in the selection.
Navigating in an M-File Feature Examples Notes Debugging navigation Lines with breakpoints that were stopped at while running, and lines stepped to A line at which you set a breakpoint is not considered as having been previously navigated to, unless it was actually stopped at during execution.
6 Editing and Debugging M-Files the split, Go > Back and Forward do not go to any lines that were visited in the lower (or right) view. Opening a Selection in an M-File You can open a subfunction, function, file, variable, or Simulink model from within a file in the Editor/Debugger. Position the cursor in the name and then right-click and select Open Selection from the context menu. Based on what the selection is, the Editor/Debugger performs a different action.
Finding Text in Files Finding Text in Files In this section... “Finding Text in the Current File” on page 6-49 “Finding and Replacing Text in the Current File” on page 6-49 “Finding Files or Text in Multiple Files” on page 6-51 “Incremental Search” on page 6-51 Finding Text in the Current File Within the current file, select the text you want to find. From the Edit menu, select Find Selection. The next occurrence of that text is selected.
6 Editing and Debugging M-Files The search begins at the current cursor position. MATLAB finds the text you specified and highlights it. To find another occurrence, click Find Next or Find Previous, or use the keyboard shortcuts F3 and Shift+F3 (or Command+F3 and Command+Shift+F3 with Macintosh key bindings). MATLAB beeps when a search for Find Next reaches the end of the file, or when a search for Find Previous reaches the top of the file.
Finding Text in Files 3 To save the changes to the file, select Save from the File menu. You can repeat this for multiple files. Function Alternative for Finding Text Use lookfor to search for the specified text in the first line of help for all M-files on the search path. Finding Files or Text in Multiple Files To find directories and filenames that include specified text, or whose contents contain specified text, use Edit > Find Files.
6 Editing and Debugging M-Files 3 In the incremental search field, type the text you want to find. For example, type plot. As you type the first letter, p, the first occurrence of that letter after the cursor is highlighted. In the example shown, the cursor is in the middle of line 2, so the first occurrence of p, the p in problem on line 2, is highlighted. Incremental search is case sensitive for uppercase letters.
Finding Text in Files • If you mistype in the incremental search field, use the backspace key to remove the last letters and make corrections. • After finding the p, press Ctrl+W to highlight the rest of the word found, in this case plot, which also puts the complete word in incremental search field. 4 To find the next occurrence of plot in the file, press Ctrl+S. To find the previous occurrence of the text, press Ctrl+R.
6 Editing and Debugging M-Files Comparing Files — File Comparison Tool In this section...
Comparing Files — File Comparison Tool • Tools > Compare Against > Autosave Version to compare the open file to the Editor/Debugger’s automatic copy, filename.asv. For more information, see “Autosave” on page 6-63. • Tools > Compare Against Version on Disk to compare an open file that has been changed but not saved to the saved version. 3 The File Comparisons tool opens, displaying the files side by side and highlighting lines that do not match.
6 Editing and Debugging M-Files 4 Use features of the File Comparisons tool to work with the results. Increase or Decrease Line Lengths Shown By default, the display is 60 columns wide for each file.
Comparing Files — File Comparison Tool vertical edges of the window to make it wider. With a narrower window size, if there are more columns shown in the left file but fewer in the right file, reduce the number for Columns visible to see enough in both sides. Exchange Positions To move the file on the left side to the right side and vice-versa, select File > Swap Sides, or click the equivalent toolbar button .
6 Editing and Debugging M-Files Alternative Ways to Access the Tool These are additional ways you can access the tool: • From the MATLAB desktop, select Desktop > File Comparisons. • From the Current Directory browser, select a file, right-click, and from the context menu, select Compare Against. • For two files in the same directory, from the Current Directory browser, select the files, right-click, and from the context menu, select Compare Selected Files.
Keyboard Shortcuts in the Editor/Debugger Keyboard Shortcuts in the Editor/Debugger Following is the list of keys that serve as shortcuts for using the Editor/Debugger. This list does not include shortcut keys (sometimes called hot keys) for menu items—you can view those on the menus. If you select the Emacs “Editor/Debugger Key Bindings” on page 3-45 preference, you can also use the Ctrl+key combinations shown. See also general desktop “Keyboard Shortcuts” on page 2-40.
6 Editing and Debugging M-Files Key or Mouse Action for Windows Preference Additional Control Key for Emacs Preference Key or Mouse Action for Macintosh Preference Operation Home Ctrl+A Cmd+ Move to beginning of line. End Ctrl+E Cmd+ Move to end of line. Delete Ctrl+D Forward Delete Delete character after cursor. Backspace none Delete Delete character before cursor. None Ctrl+K None Cut contents (kill) to end of line. Double-click None Double-click Select current word.
Keyboard Shortcuts in the Editor/Debugger Key or Mouse Action for Windows Preference Additional Control Key for Emacs Preference Key or Mouse Action for Macintosh Preference Insert None None Change to overwrite mode from insert mode, or change to insert mode from overwrite mode. View current mode in the status bar: OVR is gray for insert mode. In overwrite mode, what you type replaces existing text, and the cursor is a wide block. (Not supported on Macintosh platforms.
6 Editing and Debugging M-Files Saving, Printing, and Closing Files in the Editor/Debugger In this section... “Saving Files” on page 6-62 “Printing M-Files” on page 6-64 “Closing M-Files” on page 6-64 Saving Files After making changes to an file, you see an asterisk (*) next to the filename in the title bar of the Editor/Debugger. This indicates there are unsaved changes to the file. To save the changes, use one of the Save commands in the File menu: • Save — Saves the file using its existing name.
Saving, Printing, and Closing Files in the Editor/Debugger Note Save any M-files you create and any M-files from The MathWorks that you edit in a directory that is not in the matlabroot/toolbox directory tree. If you keep your files in matlabroot/toolbox directories, they can be overwritten when you install a new version of MATLAB. Also note that locations of files in the matlabroot/toolbox directory tree are loaded and cached in memory at the beginning of each MATLAB session to improve performance.
6 Editing and Debugging M-Files There is a preference to Automatically delete autosave files. With this preference selected, when you close an M-file in the Editor/Debugger, MATLAB automatically deletes the corresponding autosave file. Accessing Your Source Control System If you use a source control system for M-files, you can access it from within the Editor/Debugger using File > Source Control. For more information, see Chapter 9, “Source Control Interface”.
Saving, Printing, and Closing Files in the Editor/Debugger If each file is open in a separate window, close all the files at once using the Close All Documents item in the Window menu. Note that this also closes desktop documents of all types, including Array Editor documents. When you close a file that has unsaved changes, you are prompted to save the file. If you do not want to be prompted, hold Ctrl and click the Close box.
6 Editing and Debugging M-Files Running M-Files in the Editor/Debugger In this section...
Running M-Files in the Editor/Debugger General Display Options, select the check box for Enable datatips in edit mode. Using Configurations — Running M-Files with Input Arguments in the Editor/Debugger In the Editor/Debugger, you can provide values for a function’s input arguments using a configuration, and then run that configuration to use the assigned values. When you are editing a function M-file, use a configuration as an alternative to running the function in the Command Window.
6 Editing and Debugging M-Files 2 Click the down arrow on the Run button in the Editor/Debugger toolbar and select Edit Configurations for filename, where filename in this example is collatzplot_new.m. The Edit M-File Configurations dialog box opens, with a default configuration template for collatzplot_new.m.
Running M-Files in the Editor/Debugger 3 In the dialog box, enter MATLAB statements in the MATLAB expression area of the dialog box, specifying what you want to run. Delete the existing comments or replace them with comments relevant to your configuration. To undo and redo, use the keyboard shortcuts for your platform, such as Ctrl+Z and Ctrl+Y for Windows. In this example, set m equal to 3, a small value useful for debugging purposes. Complete the statement to run collatzplot_new(m).
6 Editing and Debugging M-Files The MATLAB expression area provides syntax highlighting and shows M-Lint messages, similar to the Editor/Debugger. 4 To ensure your configuration runs as expected, click Run to execute the statements in the MATLAB expression area of the dialog box. In this example, collatzplot_new(3) runs, and a figure window displays the plot.
Running M-Files in the Editor/Debugger 5 You can modify the statements in the MATLAB expression area of the dialog box and click Run to see the results of the changes. You can also modify the M-file and save the changes while the Edit M-File Configurations dialog box is open, and then click Run to see the results of the M-file changes. 6 You can assign a name using Configuration name in the Edit M-File Configurations dialog box. By default, the configuration name is the M-file name.
6 Editing and Debugging M-Files To run the configuration, select the configuration name. MATLAB runs the expression you specified in the configuration. For example, select collatzplot_new_test, and MATLAB runs collatzplot_new(3), as specified in step 3. You can modify the M-file, save it, and run the configuration from the toolbar to see the effects of the M-file changes.
Running M-Files in the Editor/Debugger • Small value, e.g., 3, for debugging and testing • Realistic value, e.g., 200 or more, for a specific project • Random value to observe changes 1 Open the Edit M-File Configurations dialog box. Select the M-file to which you want to add a configuration, or select a configuration associated with that M-file. Click the Add button (under the list of M-files and configurations). MATLAB creates a new default configuration template, in this example, collatzplot_new.
6 Editing and Debugging M-Files collatplot_new_test, described in “Create and Run a Configuration for an M-file” on page 6-67. For example, rename collatzplot_new to collatzplot_new_largevalue, and replace the default template expression with m=200; collatzplot_new(m) To create another configuration, click the Add button .
Running M-Files in the Editor/Debugger 5 Click Done to close the Edit M-File Configurations dialog box. Find Configurations 1 Open any M-file in Editor/Debugger. For example, open the MATLAB function sin. 2 Open the Edit M-File Configurations dialog box. MATLAB automatically creates a default configuration for sin.m, if none exists. In the left panel, MATLAB displays a list of all M-files containing configurations.
6 Editing and Debugging M-Files 3 Type a term in the filter field to find an M-file or configuration by name. MATLAB displays only those M-files whose names contain the term, or whose associated configurations contain the term in their name. As you type, MATLAB filters out files and configurations that do not contain the term. For example, type rand. In this example, only one M-file, collatzplot_new.m, has a configuration that contains the term rand.
Running M-Files in the Editor/Debugger 4 Expand the M-file name to see associated configurations whose names contain the term you entered in the filter field. In this example, click the expander (+ on Windows) for collatzplot_new.m to see configurations whose names contain rand. If you cannot view the entire name of a configuration, drag the separator bar to the right of the list, making the left panel wider. For the example, there is only one configuration, collatzplot_new_randomvalue.
6 Editing and Debugging M-Files 5 To see the expression in that configuration, select the configuration, or position the pointer over the name. 6 As you type additional letters in the filter field, fewer M-files remain in the list of results. Use the backspace key to modify the term. If there are no M-files or configurations containing the term, the list will be empty. 7 To clear the filter and show all M-files with configurations, click the clear button in the filter field.
Running M-Files in the Editor/Debugger 3 Select the configuration you want to delete. 4 Click the Remove button . 5 To undo the last deletion, click the Undo button . You cannot undo the last deletion after having closed the Edit M-File Configuration dialog box. Reassociate and Rename Configurations Each configuration is associated with a specific M-file. If you move or rename the M-file, you need to redefine the association.
6 Editing and Debugging M-Files To reassociate configurations 1 In the list of configurations (left pane), select the M-file. The Associated M-file displays the full path to the M-file that was associated with the configurations. Click Choose. 2 In the resulting Open dialog box, navigate to and select the M-file with which you now want to associate the configurations. Click Open In this example, you want to associate the configurations with collatzplot.m; select collatzplot.m.
Running M-Files in the Editor/Debugger 4 You might want to rename the configurations to be consistent with the new M-file name, or at least to not reflect the former M-file name. This is not required, but it is a good practice. To do so, select a configuration from the list in the left pane. In the right pane, edit the value for Configuration name. Repeat for all configurations associated with the M-file. In this example, remove collatzplot_new from the start of each configuration name.
6 Editing and Debugging M-Files 5 For an M-file name change, you might need to modify the configuration statements to run correctly. For this example, modify the collatzplot_new(m) statement in each configuration to use collatzplot(m).
Running M-Files in the Editor/Debugger See Also — Other Ways to Run M-Files from the Editor/Debugger • See “Running an M-File with Breakpoints” on page 6-111 for additional information about running M-files while debugging. • While debugging, you can execute sections of an M-file even though there are unsaved changes—see “Running Sections in M-Files That Have Unsaved Changes” on page 6-125.
6 Editing and Debugging M-Files Finding Errors, Debugging, and Correcting M-Files This section introduces general techniques for finding errors and using M-Lint automatic code analyzer to detect possible improvements in M-files. It then illustrates MATLAB debugger features found in the Editor/Debugger, as well equivalent Command Window debugging functions, using a simple example. There are two kinds of errors: • Syntax errors — For example, misspelling a function name or omitting a parenthesis.
Finding Errors, Debugging, and Correcting M-Files Technique or Tool Error Messages Description For More Information When you run an M-file with a syntax error, MATLAB will most likely detect it and display an error message in the Command Window describing the error and showing its line number in the M-file. Click the underlined portion of the error message, or position the cursor within the message and press Ctrl+Enter.
6 Editing and Debugging M-Files Technique or Tool Other Debugging Techniques Description • Add keyboard statements to the M-file — keyboard statements stop M-file execution at the point where they appear and allow you to examine and change the function’s local workspace. This mode is indicated by a special K>>prompt. Resume function execution by typing return and pressing the Enter key. For more information, see the keyboard reference page.
M-Lint Code Analyzer M-Lint Code Analyzer In this section... “What Is M-Lint?” on page 6-87 “Ways to Use M-Lint” on page 6-87 “M-Lint Automatic Code Analyzer in the Editor/Debugger” on page 6-88 “Suppressing M-Lint Indicators and Messages” on page 6-98 What Is M-Lint? The M-Lint code analyzer checks your code for problems and recommends modifications to maximize performance and maintainability.
6 Editing and Debugging M-Files M-Lint Automatic Code Analyzer in the Editor/Debugger To use the M-Lint continuous code checking in an M-file in the Editor/Debugger, perform the following steps: 1 Ensure the M-Lint messaging preference is enabled: Select File > Preferences > M-Lint and select the Enable integrated M-Lint warning and error messages check box. To follow these instructions, be sure the Underlining option is set to Underline warnings and errors. Click OK.
M-Lint Code Analyzer 2 Open an M-file in the Editor/Debugger. This example uses the sample file lengthofline.
6 Editing and Debugging M-Files open(fullfile(matlabroot,'help','techdoc','matlab_env','examples','lengthofline.m')) b Save the example file to a directory to which you have write access. For the example, lengthofline.m is saved to I:\MATLABFiles\mymfiles. 3 The M-Lint message indicator at the top right edge of the window conveys the M-Lint messages reported for the file: • Red means syntax errors were detected.
M-Lint Code Analyzer M-Lint message indicator for all messages in entire file: - Red means errors detected - Orange means warnings or improvement opportunities detected - Green means none detected Click indicator to go to next line that has an associated M-Lint message.
6 Editing and Debugging M-Files 4 Click the M-Lint message indicator to go to the next code fragment containing an M-Lint message. The next code fragment is relative to the current cursor position, viewable in the status bar. In the lengthofline example, the first message is at line 22. The cursor moves to the beginning of line 22. 5 The code fragment for which there is an M-Lint message is underlined in either red for errors or orange for warnings and improvement opportunities.
M-Lint Code Analyzer extraneous and you could delete it. But it might be that you actually intended to use the variable, as shown in step 6 of this example. 6 Make changes to your code as needed. The M-Lint indicator and underlining automatically update to reflect the changes you make, even if you do not save the file. In this example, the intention was to use nothandle as a performance improvement by determining the value prior to the loop.
6 Editing and Debugging M-Files Right-click the highlighted code (for a single-button mouse, use Ctrl+click). The first item in the context menu indicates the automatic fix that M-Lint can perform. Select it and M-Lint automatically corrects the code. In this example, M-Lint replaces prod(size(hline)) with numel(hline).
M-Lint Code Analyzer There is a preference you can set for the color—for more information, see “Other Colors” on page 2-75. 8 You might want to ignore certain M-Lint messages and do not want the messages to display; for more information, see “Suppressing M-Lint Indicators and Messages” on page 6-98. 9 You can click the M-Lint message indicator to go to the next message, or use the other way to view messages, which is the M-Lint message bar.
6 Editing and Debugging M-Files temp = diff([data{1}(:) data{2}(:) data{3}(;)]); Multiple messages can represent a single problem or multiple problems. Addressing one might address all of them, or after addressing one, the other messages might change or what you need to do might become clearer. M-Lint message bar. Each marker represents an M-Lint message. Position the pointer at a marker to view the message, in this example the only error marker in the file. There can be multiple messages for one line.
M-Lint Code Analyzer That single change addressed the issues in all of the M-Lint messages for line 48. Because the change you made removed the only error in the file, the M-Lint message indicator at the top of the bar changes from red to orange, indicating that only warnings and potential improvements remain.
6 Editing and Debugging M-Files Suppressing M-Lint Indicators and Messages Depending on what stage you are at in completing the M-file, you might want to restrict the underlining, which you can do via the M-Lint preference referred to in step 1, above. For example, when first coding, you might prefer no underlines because they would be distracting. For details, click the Help button in the Preferences dialog box.
M-Lint Code Analyzer There are a few different ways to suppress the M-Lint indicators and messages: • “Ignore Only a Specific Instance” on page 6-99 • “Disable All Instances in All Files” on page 6-101 • “Disable Specified Messages or in Selected Files as Needed” on page 6-101 Note that you cannot suppress M-Lint error messages such as syntax errors, and therefore, the following options do not apply.
6 Editing and Debugging M-Files Right-click at an M-Lint underline and select the option instructing M-Lint to ignore only this instance of the message, as shown in this example.
M-Lint Code Analyzer M-Lint adds %#ok for a specific message to the end of a line for which you specified the M-Lint message should be suppressed. Disable All Instances in All Files Right-click at the M-Lint underline (for a single-button mouse, use Ctrl+click). From the context menu, select Disable all "Terminate statement with semicolon...". Doing so modifies the M-Lint preference setting, which applies to all occurrences in all files, unless a line includes a %#ok for that message.
6 Editing and Debugging M-Files txt file. You can reuse the settings for any M-file, or provide the settings file to another user. To use the saved settings, either select the settings file in M-Lint preferences, or in the Editor/Debugger. In the Editor/Debugger, right-click the M-Lint message bar (for a single-button mouse, use Ctrl+click), or select Tools > M-Lint. The currently-selected setting choice is shown, preceded by a bullet point.
Debugging Process and Features Debugging Process and Features In this section...
6 Editing and Debugging M-Files that are on the search path. If all files to be used are in the same directory, you can instead make that directory be the current directory. Debugging Example — The Collatz Problem The debugging process and features are best described via an example. To prepare to use the example, create two M-files, collatz.m and collatzplot.m, that produce data for the Collatz problem.
Debugging Process and Features Code for collatz.m. function sequence=collatz(n) % Collatz problem.
6 Editing and Debugging M-Files Try out collatzplot to see if it works correctly. Use a simple input value, for example, 3, and compare the results to those shown in the preceding table. Typing collatzplot(3) produces the plot shown in the following figure. The plot for n = 1 appears to be correct—for 1, the Collatz series is 1, and contains one integer.
Debugging Process and Features Setting Breakpoints Set breakpoints to pause execution of the M-file so you can examine values where you think the problem might be. You can set breakpoints in the Editor/Debugger, using functions in the Command Window, or both. There are three basic types of breakpoints you can set in M-files: • A standard breakpoint, which stops at a specified line in an M-file. For details, see “Setting Standard Breakpoints” on page 6-108.
6 Editing and Debugging M-Files only stop at the for statement once. Instead place the breakpoint at the next line, m=n+1 to stop at each pass through the loop. You cannot set breakpoints while MATLAB is busy, for example, running an M-file, unless that M-file is paused at a breakpoint. Setting Standard Breakpoints To set a standard breakpoint using the Editor/Debugger, click in the breakpoint alley at the line where you want to set the breakpoint.
Debugging Process and Features Valid (Red) and Invalid (Gray) Breakpoints. Red breakpoints are valid standard breakpoints. If breakpoints are instead gray, they are not valid.
6 Editing and Debugging M-Files Breakpoints are gray for either of these reasons: • The file has not been saved since changes were made to it. Save the file to make breakpoints valid. The gray breakpoints become red, indicating they are now valid. Any gray breakpoints that were entered at invalid breakpoint lines automatically move to the next valid breakpoint line with the successful file save. • There is a syntax error in the file.
Debugging Process and Features Some useful related functions are • dbtype — Lists the M-file with line numbers in the Command Window. • dbstatus — Lists breakpoints. Running an M-File with Breakpoints After setting breakpoints, run the M-file from the Command Window or the Editor/Debugger.
6 Editing and Debugging M-Files • The function displayed in the Stack field on the toolbar changes to reflect the current function (sometimes referred to as the caller or calling workspace). The call stack includes subfunctions as well as called functions. If you use debugging functions from the Command Window, use dbstack to view the current call stack.
Debugging Process and Features Toolbar Button Debug Menu Item Description Function Alternative Step Execute the current line of the M-file. dbstep Step In Execute the current line of the M-file and, if the line is a call to another function, step into that function. dbstep in Step Out After stepping in, run the rest of the called function or subfunction, leave the called function, and pause. dbstep out Continue Running in the Example In the example, collatzplot is paused at line 10.
6 Editing and Debugging M-Files Examining Values While the program is paused, you can view the value of any variable currently in the workspace. Examine values when you want to see whether a line of code has produced the expected result or not. If the result is as expected, continue running or step to the next line. If the result is not as expected, then that line, or a previous line, contains an error.
Debugging Process and Features Viewing Values as Datatips in the Editor/Debugger In the Editor/Debugger, position the pointer to the left of a variable on that line. Its current value appears — this is called a datatip, which is like a tooltip for data. The datatip stays in view until you move the pointer. If you have trouble getting the datatip to appear, click in the line and then move the pointer next to the variable. A related function is datatipinfo. Datatips in the Example.
6 Editing and Debugging M-Files Command Window and MATLAB displays its current value. For the example, to see the value of n, type n MATLAB returns the expected result n = 2 and displays the debug prompt, K>>. Viewing Values in the Workspace Browser and Array Editor You can view the value of variables in the Value column of the Workspace browser. The Workspace browser displays all variables in the current workspace.
Debugging Process and Features and the Array Editor opens, showing that n = 2 as expected. Evaluating a Selection Select a variable or equation in an M-file in the Editor/Debugger. Right-click and select Evaluate Selection from the context menu (for a single-button mouse, use Ctrl+click). MATLAB displays the value of the variable or equation in the Command Window. You cannot evaluate a selection while MATLAB is busy, for example, running an M-file.
6 Editing and Debugging M-Files calling function, which automatically runs the rest of the called function and returns to the next line in the calling function. To step out, use the Step Out button or type dbstep out in the Command Window. In collatzplot, step again to advance to line 11, then line 12. The variable seq_length in line 11 is a vector with the elements 1 2 which is correct. Finally, step again to advance to line 13.
Debugging Process and Features program is paused, assign a new value to the variable in the Command Window, Workspace browser, or Array Editor. Then continue running or stepping through the program. If the new value does not produce the expected results, the program has a different problem. Ending Debugging After identifying a problem, end the debugging session. You must end a debugging session if you want to change and save an M-file to correct a problem, or if you want to run other functions in MATLAB.
6 Editing and Debugging M-Files Disabling and Enabling Breakpoints. You can disable selected breakpoints so the program temporarily ignores them and runs uninterrupted, for example, after you think you identified and corrected a problem. This is especially useful for conditional breakpoints — see “Conditional Breakpoints” on page 6-126.
Debugging Process and Features dbclear all in collatzplot Breakpoints are automatically cleared when you • End the MATLAB session • Clear the M-file using clear name or clear all Note When clear name or clear all is in a statement in an M-file that you are debugging, it clears the breakpoints. Saving Breakpoints You can use the s=dbstatus syntax and then save s to save the current breakpoints to a MAT-file. At a later time, you can load s and restore the breakpoints using dbstop(s).
6 Editing and Debugging M-Files 1 End the debugging session. One way to do this is to select Exit Debug Mode from the Debug menu. 2 In collatzplot.m line 12, change the string plot_seq to seq_length(N) and save the file. 3 Clear the breakpoints in collatzplot.m. One way to do this is by typing dbclear all in collatzplot in the Command Window. 4 Run collatzplot for m = 3 by typing collatzplot(3) in the Command Window. 5 Verify the result.
Debugging Process and Features 6 Test the function for a slightly larger value of m, such as 6, to be sure the results are still accurate. To make it easier to verify collatzplot for m = 6 as well as the results for collatz, add this line at the end of collatz.m sequence which displays the series in the Command Window.
6 Editing and Debugging M-Files collatzplot(6) 7 To make debugging easier, you ran collatzplot for a small value of m. Now that you know it works correctly, run collatzplot for a larger value to produce more interesting results. Before doing so, you might want to disable output for the line you just added in step 6, line 19 of collatz.
Debugging Process and Features The following figure shows the lengths of the Collatz series for n = 1 through n = 500. Running Sections in M-Files That Have Unsaved Changes It is a good practice to make changes to an M-file after you quit debugging, and to save the changes and then run the file. Otherwise, you might get unexpected results.
6 Editing and Debugging M-Files choose Evaluate Selection from the context menu. You can also use cell mode to do this. Conditional Breakpoints Set conditional breakpoints to cause MATLAB to stop at a specified line in a file only when the specified condition is met. One particularly good use for conditional breakpoints is when you want to examine results after a certain number of iterations in a loop.
Debugging Process and Features The MATLAB Editor conditional breakpoint dialog box opens as shown in this example. 2 Type a condition in the dialog box, where a condition is any legal MATLAB expression that returns a logical scalar value. Click OK. As noted in the dialog box, the condition is evaluated before running the line. For the example, at line 10 in collatzplot, enter N>=2 as the condition.
6 Editing and Debugging M-Files Copying, Modifying, Disabling, and Clearing Conditional Breakpoints To copy a conditional breakpoint, right-click the icon in the breakpoint alley and select Copy from the context menu. Then right-click in the breakpoint alley at the line where you want to paste the conditional breakpoint and select Paste from the context menu. Modify the condition for the breakpoint in the current line by selecting Set/Modify Conditional Breakpoint from the Debug or context menu.
Debugging Process and Features that line and select the action. MATLAB prompts you to specify the exact breakpoint on which to act in that line. When you set a breakpoint in an anonymous function, MATLAB stops when the anonymous function is called. The following illustration shows the Editor/Debugger when you set a breakpoint in the anonymous function sqr in line 2, and then run the file. MATLAB stops when it runs sqr in line 4.
6 Editing and Debugging M-Files • “Function Alternative for Error Breakpoints” on page 6-132 Setting Error Breakpoints To set error breakpoints, select Debug > Stop if Errors/Warnings. In the resulting Stop if Errors/Warnings for All Files dialog box, specify error breakpoints on all appropriate tabs and click OK. To clear error breakpoints, select the Never stop if ... option for all appropriate tabs and click OK.
Debugging Process and Features Errors. When an error occurs, execution stops, unless the error is in a try...catch block. MATLAB enters debug mode and opens the M-file to the line in the try portion of the block that produced the error. You cannot resume execution. Try/Catch Errors. When an error occurs in a try...catch block, execution pauses. MATLAB enters debug mode and opens the M-file to the line that produced the error. You can resume execution or use debugging features. Warnings.
6 Editing and Debugging M-Files Message Identifier dialog box. An example of an error message identifier is MATLAB:UndefinedFunction. Similarly, to obtain a warning message identifier, produce the warning and then run [m,id] = lastwarn; MATLAB returns the last warning identifier to id. An example of a warning message identifier is MATLAB:divideByZero. Function Alternative for Error Breakpoints The function equivalent for each option appears in the Stop if Errors/Warnings for All Files dialog box.
Using Cells for Rapid Code Iteration and Publishing Results Using Cells for Rapid Code Iteration and Publishing Results In this section... “What Are Cells?” on page 6-133 “Rapid Code Iteration Overview” on page 6-133 “Defining Cells” on page 6-135 “Navigating and Evaluating with Cells” on page 6-139 “Using Cells in Function M-Files” on page 6-144 What Are Cells? M-files often have a natural structure consisting of multiple sections.
6 Editing and Debugging M-Files If you have an active Internet connection, you can watch the Rapid Code Iteration Using Cells video demo for an overview of the major functionality. This is the overall process of using cells for rapid code iteration: 1 In the MATLAB Editor/Debugger, enable cell mode by selecting Cell > Enable Cell Mode. Items in the Cell menu become selectable. The cell toolbar appears, unless you had previously hidden it.
Using Cells for Rapid Code Iteration and Publishing Results Defining Cells Cell features operate on cells, where a cell is contiguous lines of code you want to evaluate as a whole in an M-file script. To define a cell, first be sure that cell mode is enabled (see step ). Position the cursor just before the line at which you want to start the cell and select Cell > Insert Cell Divider or click the Insert Cell Divider button .
6 Editing and Debugging M-Files lines of code you want in a cell and then select Cell > Insert Cell Dividers Around Selection. You can define a cell at the start of a new empty file, enter code for the cell, define the start of the next cell, enter its code, and so on. Redefine cells by defining new cells, removing existing cells, and moving lines of code. You can set an Editor/Debugger preference to show a faint gray horizontal line (rule) above each cell that helps distinguish the cells.
Using Cells for Rapid Code Iteration and Publishing Results Example — Define Cells This example defines two cells for a simple M-file called sine_wave, shown in the following code and figure. The first cell creates the basic results, while the second label the plot. The two cells in this example allow you to experiment with the plot of the data first, and then when that is final, change the plot properties to affect the style of presentation. % Define the range for x. % Calculate and plot y = sin(x).
6 Editing and Debugging M-Files 2 Position the cursor at the start of the first line. Select Cell > Insert Cell Divider. The Editor/Debugger inserts %% as the first line and moves the rest of the file down one line. All lines are highlighted in yellow, indicating that the entire file is a single cell, unless you do not have that display preference for cells selected. 3 Enter a cell title following the %%. Type a space first, followed by the description.
Using Cells for Rapid Code Iteration and Publishing Results Removing Cells To remove a cell, delete one of the percent signs (%) from the line that starts the cell. This changes the line from a cell to a standard comment and merges the cell with the preceding cell. You can also just delete the entire line that contains the %%.
6 Editing and Debugging M-Files 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 equivalent buttons in the cell toolbar.
Using Cells for Rapid Code Iteration and Publishing Results Modifying Values in a Cell You can use cell features to modify numbers in a cell, which also automatically reevaluates the cell. This helps you experiment with and fine-tune your code. 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.
6 Editing and Debugging M-Files 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 . Line 4 becomes and the length of x doubles. The plot automatically updates. The curve still has some rough edges. 3 To add more values for x, click the Divide button three more times.
Using Cells for Rapid Code Iteration and Publishing Results 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. 4 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. The resulting curve is still smooth. 5 Save these changes. Select File > Save.
6 Editing and Debugging M-Files MATLAB updates the figure. Using Cells in Function M-Files You can define and evaluate cells in function M-files as long as the variables referred to in the cell are in your workspace. For example, this can be useful during debugging. If execution is stopped at a breakpoint, you can define cells and execute them without saving the file. If you are not debugging, add the necessary variables to the base workspace and then execute the cells.
7 Tuning and Managing M-Files This set of tools provides useful information about the M-files in a directory that can help you refine the files and improve performance. The tools can help you polish M-files before providing them to others to use. If you have an active Internet connection, you can watch the Directory Reports video demo for an overview of the major functionality. Directory Reports in Current Directory Browser (p.
7 Tuning and Managing M-Files Directory Reports in Current Directory Browser In this section... “Accessing and Using Directory Reports” on page 7-2 “TODO/FIXME Report” on page 7-4 “Help Report” on page 7-6 “Contents Report” on page 7-9 “Dependency Report” on page 7-13 “Coverage Report” on page 7-15 See also another Directory Report, “M-Lint Code Check Report” on page 7-16, and the File Comparisons tool.
Directory Reports in Current Directory Browser The report you selected appears as an HTML document in the MATLAB Web Browser: • In a report, click a filename to open that file in the Editor/Debugger, where you can view it or make changes to it. Click a line number to open the file at that line. • To update a report after making changes to the report options, or after changing any files in the directory, click Rerun This Report.
7 Tuning and Managing M-Files TODO/FIXME Report The TODO/FIXME Report shows M-files that contain text strings you included as notes to yourself, such as TODO. Use this report to easily identify M-files that still require work or some other actions. To access this report, follow the instructions in “Accessing and Using Directory Reports” on page 7-2. In the report, select one or more check boxes to display lines containing the specified strings (TODO and FIXME), and click Rerun This Report.
Directory Reports in Current Directory Browser 7-5
7 Tuning and Managing M-Files Help Report The Help Report presents a summary view of the help component of your M-files. In MATLAB, the M-file help component is all contiguous nonexecutable lines (comment lines and blank lines), starting with the second line of a function M-file or the first line of a script M-file. For more information about creating help for your own M-files, see the reference page for the help function.
Directory Reports in Current Directory Browser Show Subfunctions With Show subfunctions selected, the Help Report displays help information for all subfunctions called by each function. Help information for subfunctions is highlighted in gray.
7 Tuning and Managing M-Files Description With Description selected, the Help Report displays the first line of help in the M-file. If the first comment line is empty, or if there is not a comment before the executable code, No description line, highlighted in pink, appears instead. Examples With Examples selected, the Help Report displays the line number where the examples section of the M-file help begins.
Directory Reports in Current Directory Browser The report looks for a line in the M-file help that begins with the string See also. If the report does not find a see also line in the M-file help, No see-also line, highlighted in pink, appears. This helps you identify those M-files without a see also line, should you want to include one in each M-file. The report also indicates when an M-file noted in the see also line is not in a directory on the search path.
7 Tuning and Managing M-Files To access this report, follow the instructions in “Accessing and Using Directory Reports” on page 7-2. If there is no Contents.m file for the directory and you run the Contents Report, the report tells you the Contents.m file does not exist and asks if you want to create one. Click yes to automatically create the Contents.m file. Edit the Contents.
Directory Reports in Current Directory Browser Use the links displayed for each line, or edit the Contents.m file directly, or edit the M-files to make the changes. To make all of the suggested changes at once, click fix all. To automatically align the filenames and descriptions in the Contents.m file, click fix spacing.
7 Tuning and Managing M-Files If you always want the Contents.m file to reflect all files in the directory, you can automatically generate a new Contents.m file rather than changing the file based on the Contents Report. To do this, first delete the existing Contents.m file, run the Contents Report, and click yes when prompted for MATLAB to automatically create one. Messages in the Contents File Report No Contents File. This message appears if there is no Contents.m file in the directory.
Directory Reports in Current Directory Browser Files Not In Contents.m. This message appears when a file in the directory is not in Contents.m. These messages are highlighted in gray. Click yes to add the filename and its description line from the M-file help to the Contents.m file. collatzall is in the directory but not Contents.
7 Tuning and Managing M-Files The Dependency Report is similar to running the depfun function, although the two do not provide the exact same results. For performance purposes, the Dependency Report limits the functions considered. Select Show parent functions to list the M-files that call each M-file. The report limits the parent (calling) functions to those in the current directory. Select Show subfunctions to include subfunctions in the report.
Directory Reports in Current Directory Browser Coverage Report Run the Coverage Report after you run the Profiler to identify how much of a file ran when it was profiled. For example, when you have an if statement in your code, that section might not run during profiling, depending on conditions. You can run the Coverage Report from the Profiler, or follow these steps: 1 In the MATLAB desktop, select Desktop > Profiler. Profile an M-file in the Profiler.
7 Tuning and Managing M-Files M-Lint Code Check Report In this section... “Running the M-Lint Code Check Directory Report” on page 7-16 “Making Changes Based on M-Lint Messages” on page 7-18 “Other Ways to Access M-Lint” on page 7-26 Running the M-Lint Code Check Directory Report The M-Lint Code Check Report displays potential errors and problems, as well as opportunities for improvement in your code. The term “lint” is the name given to similar tools used with other programming languages such as C.
M-Lint Code Check Report Line number and message describing a potential problem or improvement opportunity. Click a line number to open the M-file in the Editor/Debugger at the line. 4 For each message, review the suggestion and your code, click the line number to open the M-file in the Editor/Debugger at that line, and make changes based on the message.
7 Tuning and Managing M-Files • M-Lint does not provide perfect information about every situation and in some cases, you might not want to make any changes based on the M-Lint message. In the event you do not want to change the code but you also do not want to see the M-Lint message for that line in the M-Lint Report, instruct M-Lint to ignore a line by adding %#ok to the end of the line in the M-file. (You can override the %#ok by running the mlint function with the '-notok' tag.
M-Lint Code Check Report • Use the Help browser Search and Index panes to find documentation about terms presented in the M-Lint messages.
7 7-20 Tuning and Managing M-Files
M-Lint Code Check Report Messages and Resulting Changes for the lengthofline Example. The following table describes each message and demonstrates a way to change the file, based on the message. Message — Code (Original Line Numbers) 22: The value assigned here to variable 'nothandle' might never be used. ————————————————— 22 nothandle = ~ishandle(hline); 23 for nh = 1:prod(size(hline)) 24 notline(nh) = ~ishandle(hline(nh)) ...
7 Tuning and Managing M-Files Message — Code (Original Line Numbers) 24: 'notline' might be growing inside a loop. Consider preallocating for speed. ————————————————— 22 nothandle = ~ishandle(hline); 23 for nh = 1:numel(hline) 24 notline(nh) = ~ishandle(hline(nh)) ... Explanation and Updated Code (New Line Numbers) When you increase the size of an array within a loop, it is inefficient. Before the loop, preallocate the array to its maximum size to improve performance.
M-Lint Code Check Report Message — Code (Original Line Numbers) Explanation and Updated Code (New Line Numbers) 34: 'data' might be growing inside a loop. Consider preallocating for speed. See the same message and explanation reported for line 24. Add this line, 34, before the loop ————————————————— data = cell(size(fdata)); 33 for nd = 1:length(fdata) 34 data{nd} = getfield(flds,fdata{nd}); 34: Use dynamic fieldnames with structures instead of GETFIELD. Type 'doc struct' for more information.
7 Tuning and Managing M-Files Message — Code (Original Line Numbers) 42: 'data' might be growing inside a loop. Consider preallocating for speed. ————————————————— 42 data{3} = zeros(size(data{1})); This message no longer appears due to the change made to line 34 data{nd} = getfield(flds,fdata{nd});. Sometimes fixing code in one line automatically clears a message for another line.
M-Lint Code Check Report Message — Code (Original Line Numbers) 49: Terminate statement with semicolon to suppress output (in functions). Explanation and Updated Code (New Line Numbers) Adding a semicolon to the end of a statement suppresses output and is a common practice. M-Lint alerts you to lines that produce output but lack the terminating semicolon. If you want to view output from this line, do not add the semicolon.
7 Tuning and Managing M-Files Updated M-Lint Code Check Report after making changes to the lenghtofline file based on M-Lint messages. Now, no messages are reported. The M-file that includes all of the changes suggested by M-Lint is lengthofline2.m. To view it, run edit(fullfile(matlabroot,'help','techdoc','matlab_env',... 'examples','lengthofline2.m')). Other Ways to Access M-Lint You can get M-Lint messages using any of the following methods.
Profiling for Improving Performance Profiling for Improving Performance In this section... “What Is Profiling?” on page 7-27 “Profiling Process and Guidelines” on page 7-28 “Using the Profiler” on page 7-29 “Profile Summary Report” on page 7-33 “Profile Detail Report” on page 7-35 “The profile Function” on page 7-42 What Is Profiling? Profiling is a way to measure where a program spends time.
7 Tuning and Managing M-Files Profiling Process and Guidelines Here is a general process you can follow to use the Profiler to improve performance in your M-files. This section also describes how you can use profiling as a debugging tool and as a way to understand complex M-files. Note Premature optimization can increase code complexity unnecessarily without providing a real gain in performance. Your first implementation should be as simple as possible.
Profiling for Improving Performance Using Profiling as a Debugging Tool The Profiler is a useful tool for isolating problems in your M-files. For example, if a particular section of the file did not run, you can look at the detail reports to see what lines did run, which might point you to the problem. You can also view the lines that did not run to help you develop test cases that exercise that code. If you get an error in the M-file when profiling, the Profiler provides partial results in the reports.
7 Tuning and Managing M-Files For information about the reports generated by the Profiler, see “Profile Summary Report” on page 7-33 and “Profile Detail Report” on page 7-35. Opening the Profiler You can use any of the following methods to open the Profiler: • Select Desktop > Profiler from the MATLAB desktop. • Click the Profiler button in the MATLAB desktop toolbar. • With a file open in the MATLAB Editor/Debugger, select Tools > Open Profiler.
Profiling for Improving Performance To profile an M-file or a line of code, follow these steps: 1 In the Run this code field in the Profiler, type the statement you want to run. You can run this example [t,y] = ode23('lotka',[0 2],[20;20]) as the code is provided with MATLAB demos. It runs the Lotka-Volterra predator-prey population model. For more information about this model, type lotkademo, which runs the demonstration.
7 Tuning and Managing M-Files 2 Click Start Profiling (or press Enter after typing the statement). While the Profiler is running, the Profile time indicator (at the top right of the Profiler window) is green and the number of seconds it reports increases. When the profiling is finished, the Profile time indicator becomes black and shows the length of time the Profiler ran. The statements you profiled are shown as having been executed in the Command Window.
Profiling for Improving Performance 2 Start the graphical user interface. (If you do not want to include its startup process in the profile, do not click Start Profiling, step 1, until after you have started the graphical interface.) 3 Use the graphical interface. When you are finished, click Stop Profiling in the Profiler. The Profile Summary report appears in the Profiler.
7 Tuning and Managing M-Files order by the amount of time they took to process. To sort the functions alphabetically, click the Function Name link at the top of the column. • Calls — The number of times the function was called while profiling was on. To sort the report by the number of times functions were called, click the Calls link at the top of the column. • Total Time — The total time spent in a function, including all child functions called, in seconds.
Profiling for Improving Performance Profile Detail Report The Profile Detail report shows profiling results for a selected function that was called during profiling. A Profile Detail report is made up of seven sections, summarized below. By default, the Profile Detail report includes all seven sections, although, depending on the function, not every section contains data. To return to the Profile Summary report from the Profile Detail report, click the Home button in the toolbar.
7 Tuning and Managing M-Files Controlling the Contents of the Detail Report Display (p. 7-36) Customize display to include only sections you are interested in. Profile Detail Report Header (p. 7-38) Provides general information about the function. Parent Functions (p. 7-38) Provides information about the parent function. Busy Lines (p. 7-38) Lists the lines in the function that used the greatest amount of processing time. Child Functions (p. 7-39) M-Lint Results (p.
Profiling for Improving Performance 7-37
7 Tuning and Managing M-Files Profile Detail Report Header The detail report header includes the name of the function that was profiled, the number of times it was called in the parent function, and the amount of time it used. The header includes a link that opens the function in your default text editor. The header also includes a link that copies the report to a separate window.
Profiling for Improving Performance Note that this was not selected in the example. Click a line number to view that line of code in the source listing. Child Functions To include the Children section of the detail report, select the Show child functions check box. This section of the report lists all the functions called by the profiled function. If the called function is an M-file, you can view the source code for the function by clicking its name.
7 Tuning and Managing M-Files M-Lint Results To include the M-Lint results section in the detail report display, select the Show M-Lint results check box. This section of the report provides information about problems and potential improvements, generated by M-Lint about the function. For more information about M-Lint, see “M-Lint Code Check Report” on page 7-16. File Coverage To include the Coverage results section in the detail report display, select the Show file coverage check box.
Profiling for Improving Performance Function Listing To include the Function listing section in the detail report display, select the Show function listing check box. If the file is an M-file, the Profile Detail report includes a column listing the execution time for each line, a column listing the number of times the line was called, and the source code for the function.
7 Tuning and Managing M-Files The profile Function The Profiler is based on the results returned by the profile function.
Profiling for Improving Performance profile Function Syntax Summary Here is a summary of some of the main forms of profile. For details about these and other options, type doc profile. Some people use profile simply to see the child functions; see also depfun for that purpose. Syntax Description profile on Starts profile, clearing previously recorded statistics.
7 Tuning and Managing M-Files 1 To start profile, type in the Command Window profile on 2 Execute an M-file. This example runs the Lotka-Volterra predator-prey population model. For more information about this model, type lotkademo, which runs a demonstration. [t,y] = ode23('lotka',[0 2],[20;20]); 3 Generate the profile report and display it in the Profiler window. This suspends profile. profile viewer 4 Restart profile, without clearing the existing statistics.
Profiling for Improving Performance 7 To save the profile report, use the profsave function. This function stores the profile information in separate HTML files, for each function listed in FunctionTable of p. profsave(p) By default, profsave puts these HTML files in a subdirectory of the current directory named profile_results, and displays the summary report in your system browser. You can specify another directory name as an optional second argument to profsave.
7 Tuning and Managing M-Files ClockSpeed: 3.0000e+009 Name: 'MATLAB' 5 The FunctionTable field is an array of structures, where each structure represents an M-function, M-subfunction, MEX-function, or, because the builtin option is specified, a MATLAB built-in function. stats.FunctionTable ans = 41x1 struct array with fields: CompleteName FunctionName FileName Type NumCalls TotalTime TotalRecursiveTime Children Parents ExecutedLines IsRecursive PartialData 6 View the second structure in FunctionTable.
Profiling for Improving Performance IsRecursive: 0 PartialData: 0 7 To view the history data generated by profile, view the FunctionHistory, for example, stats.FunctionHistory. The history data is a 2-by-n array. The first row contains Boolean values, where 0 (zero) means entrance into a function and 1 means exit from a function. The second row identifies the function being entered or exited by its index in the FunctionTable field.
7 7-48 Tuning and Managing M-Files
8 Publishing Results MATLAB provides two different approaches for publishing: using cells and with the Notebook features for Microsoft Word. Publishing to HTML, XML, LaTeX, Word, and PowerPoint Using Cells (p. 8-2) Use cells to publish M-files, including code, comments, and results, to popular output formats. Marking Up Text in Cells for Publishing (p. 8-11) Prepare an M-file for publishing. Publishing M-Files Using Cells (p. 8-24) Publish an M-file and set preferences for publishing.
8 Publishing Results Publishing to HTML, XML, LaTeX, Word, and PowerPoint Using Cells In this section...
Publishing to HTML, XML, LaTeX, Word, and PowerPoint Using Cells the start of a cell appear as plain text. Comments appearing after code in a cell appear as unformatted M-file comments in the published document. 2 Use Cell > Insert Text Markup to insert markup symbols in the M-file comments to stylize the text for the output, for example, to display specified text as bold or monospaced. For details, see “Marking Up Text in Cells for Publishing” on page 8-11.
8 Publishing Results within the M-file script, supply any input values that you had passed when you ran the function. Example of Publishing Without Text Markup This is based on the M-file script used in “Example — Evaluate Cells” on page 6-141, as shown here. Instructions for preparing and publishing the file follow.
Publishing to HTML, XML, LaTeX, Word, and PowerPoint Using Cells Select File > Publish to HTML to produce the following result.
8 Publishing Results Example of Publishing with Text Markup This simple example adds text markup to the sine_wave.m file used in “Example of Publishing Without Text Markup” on page 8-4 to produce the following published HTML document.
Publishing to HTML, XML, LaTeX, Word, and PowerPoint Using Cells 8-7
8 Publishing Results 1 Add an overall title and introduction for the published document a Select Cell > Insert Text Markup > > Document Title and Introduction. MATLAB adds the following at the top of the file. %% DOCUMENT TITLE % INTRODUCTORY TEXT The two percent signs (%%) indicate the start of a new cell, where a cell is a section of an M-file. A single percent sign indicates a comment line. b Replace DOCUMENT TITLE with Plot Sine Wave.
Publishing to HTML, XML, LaTeX, Word, and PowerPoint Using Cells c Replace the sample equation with the following TeX equation: 0 \leq x \leq 6\pi The three lines that display the TeX equation in the published document now appear as follows in the M-file. % % $$0 \leq x \leq 6\pi$$ % 3 Display a selected comment text in a monospace font, as follows: a Position the cursor in the following comment, which appears in line 9. % Calculate and plot y = sin(x).
8 8-10 Publishing Results
Marking Up Text in Cells for Publishing Marking Up Text in Cells for Publishing In this section...
8 Publishing Results • Type the markup symbols directly in the code. Note that what you type is the same as the code that results if you instead use the equivalent menu item. The following tables describe each markup option and how to use it.
Marking Up Text in Cells for Publishing Format Overall document heading and introductory text How to Produce Format Resulting Code Published Results 1 Position the cursor %% DOCUMENT TITLE % INTRODUCTORY TEXT Document title is formatted as a top-level heading (h1 in HTML), using a large size, bold font. anywhere in the editor. In the example, the overall heading is %% Plot Sine Wave 2 Select Cell > Insert Text Markup > Document Title and Introduction. Introductory text appears as formatted text.
8 Publishing Results Text Markup for Indented Text, Lists, and Graphics Indented text, lists, and graphics are types of block styles. Block styles control the appearance of large sections of text within the final published document. A block is a series of comment lines within a cell’s descriptive text that starts and ends with a blank comment line, or the beginning or end of the descriptive text.
Marking Up Text in Cells for Publishing Format How to Produce Format Image 1 Position the cursor before the line where you want to add a graphic. Resulting Code and Explanation Published Results % <> If you replace FILENAME.PNG with surfpeaks.jpg, the published results appear as follows: 2 Select Cell > Insert Text Markup > Image. 3 Replace the sample text inserted, FILENAME.PNG, with filename of the graphic you want to insert. Keep the percent sign (%) and angle brackets (<< >>) .
8 Publishing Results Format How to Produce Format Resulting Code and Explanation 1 Position the cursor % * ITEM1 % * ITEM2 Bulleted list before the line where you want to add a bulleted list. Published Results • ITEM1 • ITEM2 The asterisk (*) at the start of a line indicates it is a bulleted list item. 2 Select Cell > Insert Text Markup > Bulleted List. 3 Replace the sample text inserted, ITEM 1 and ITEM 2, with your desired text.
Marking Up Text in Cells for Publishing Text Markup for HTML, LaTeX, and TeX Equation Output Types You can specify the output type for a published M-file as HTML, LaTeX or TeX equation. When you publish the M-file, use the File > Publish to menu options accordingly. For details, see “Publishing M-Files Using Cells” on page 8-24. Note When you markup text for the HTML or LaTex output type, that text is published only when the specified output type matches the markup type.
8 Publishing Results Format How to Produce Format HTML markup 1 Position the cursor before the line where you want to add HTML markup. 2 Select Cell > Insert Text Markup > HTML Markup. 3 Replace the inserted HTML markup (as shown in the next column) with your desired text. Be careful, however, to keep the percent signs (%) at the beginning of each line.
Marking Up Text in Cells for Publishing Format How to Produce Format LaTeX markup 1 Position the cursor before the line where you want to add LaTeX markup. 2 Select Cell > Insert Text Markup > LaTeX Markup. Resulting Code Published Results % % \begin{tabular}{|r|r} % \hline $n$&$n!$\\ \\hline 1&1\\ 2&2\\ 3&6\\ \\hline % \end{tabular} % 3 Replace the inserted LaTeX markup (as shown in the next column) with your desired text.
8 Publishing Results Text Markup for Bold, Italic, and Monospaced Text Formats You can mark up selected strings in the M-file comments so that they appear in bold, italic or monospaced text formats when you publish the M-file. Format How to Produce Format Resulting Code Published Results Bold text Follow these steps to bold existing text: % *BOLD TEXT* BOLD TEXT 1 Within a comment, select text that you want to be bold. 2 Select Cell > Insert Text Markup > Bold Text.
Marking Up Text in Cells for Publishing Format How to Produce Format Resulting Code Published Results Italic text Follow these steps to bold existing text: % _ITALIC TEXT_ ITALIC TEXT % |MONOSPACED TEXT| MONOSPACED TEXT 1 Within a comment, select text that you want to be italic. 2 Select Cell > Insert Text Markup > Italic Text. To insert sample text, that you will replace with your desired text, follow these steps: 1 Select Cell > Insert Text Markup > Italic Text.
8 Publishing Results Text Markup for Inline Links When you specify hypertext links within an M-file, when you publish the document the hypertext links become active links to a URL on the web.
Marking Up Text in Cells for Publishing Format How to Produce Format Resulting Code Published Results URL as hyperlinked text % > http://www.mathworks.com 1 Within a comment, position % > The MathWorks the cursor where you want to insert the hypertext link. 2 Select Cell > Insert Text Markup > Hyperlinked Text. The Editor/Debugger inserts the following code: 3 Replace www.mathworks.
8 Publishing Results Publishing M-Files Using Cells In this section... “How to Publish an M-File” on page 8-24 “About Published M-Files” on page 8-25 “Modifying Published Output Using Preferences” on page 8-26 How to Publish an M-File When you publish an M-file that contains cells and text markup, MATLAB produces an output document consisting of the M-file code, comments, and results.
Publishing M-Files Using Cells Note Publishing to Microsoft Word and to PowerPoint features are available only on Windows systems that have the applications installed. Supported Word and PowerPoint versions are 2000, 2002, 2003, and 2007. The published file contains the formatted comments, code with syntax highlighting and a gray background to distinguish it from results, and results for each cell.
8 Publishing Results TeX equations are image files as well; in the example, the equation file is sine_wave_eq_eq####.png. MATLAB creates a thumbnail file for the document, sine_wave_img_thumbnail.png in the example, if that preference is selected — see in the online documentation. Publishing Code that Displays Hyperlinks in Command Window If the M-file you publish contains statements that display hyperlinks in the MATLAB Command Window, the published document shows the code rather than the hyperlinks.
Notebook for Publishing to Word Notebook for Publishing to Word In this section...
8 Publishing Results Creating or Opening an M-Book Creating an M-Book from MATLAB To create a new M-book from within MATLAB, type notebook in the Command Window. If you are running Notebook for the first time, you might need to configure it. See “Configuring Notebook” on page 8-53 for more information. Notebook starts Microsoft Word on your system and creates a new M-book, called Document1. When Word is opening, if a dialog box appears asking you to enable or disable macros, choose to enable macros.
Notebook for Publishing to Word • In Word 2007, Notebook adds the Notebook menu to the Word Add-Ins tab, as shown in the following illustration. Use this menu to access Notebook features.
8 Publishing Results Microsoft product screen shot reprinted with permission from Microsoft Corporation.
Notebook for Publishing to Word Microsoft product screen shot reprinted with permission from Microsoft Corporation. Opening an Existing M-Book You can use the notebook command to open an existing M-book notebook filename where filename is the M-book you want to open. Or you can double-click an M-book file in a Windows file management tool, such as Explorer.
8 Publishing Results When you double-click on an M-book, Microsoft Word opens the M-book and starts MATLAB if it is not already running. Notebook adds the Notebook menu to the Word menu bar and adds New M-book to the File menu. Converting a Word Document to an M-Book To convert a Word document to an M-book, follow these steps, depending on the version of Word you are using: • Microsoft Word 2000, 2002, or 2003: 1 Create a new M-book. 2 From the Insert menu, select File.
Notebook for Publishing to Word 3 Select the file you want to convert. 4 Click OK. • Microsoft Word 2007: 1 Create a new M-book. 2 From the Insert tab, in the Text group, click the arrow next to Object and then click Text from File, as shown in the image that follows. The Insert File dialog box opens. 3 In the Insert File dialog box, select the file that you want to convert, and then click OK. Microsoft product screen shot reprinted with permission from Microsoft Corporation.
8 Publishing Results Entering MATLAB Commands in an M-Book Note A good way to learn how to use Notebook is to open the sample M-book, Readme.doc, and try out the various techniques described in this section. You can find this file in the matlabroot/notebook/pc directory. You enter MATLAB commands in an M-book the same way you enter text in any other Word document. For example, you can enter the following text in a Word document.
Notebook for Publishing to Word Ensuring Data Consistency in M-Books 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.
8 Publishing Results Defining MATLAB Commands as Input Cells for Notebook In this section... “Defining Commands as Input Cells for Notebook” on page 8-36 “Defining Cell Groups for Notebook” on page 8-37 “Defining Autoinit Input Cells for Notebook” on page 8-38 “Defining Calc Zones for Notebook” on page 8-38 “Converting an Input Cell to Text with Notebook” on page 8-39 For information about evaluating the input cells you define, see “Evaluating MATLAB Commands with Notebook” on page 8-41.
Defining MATLAB Commands as Input Cells for Notebook Defining Cell Groups for Notebook You can collect several input cells into a single input cell. This is called a cell group. Because 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.
8 Publishing Results • If you select part or all of an output cell but not its input cell, Notebook includes the input cell in the cell group. When you create a cell group, Notebook defines it as an input cell unless its first line is an autoinit cell, in which case Notebook defines the group as an autoinit cell. Defining Autoinit Input Cells for Notebook You can use autoinit cells to specify MATLAB commands to be automatically evaluated each time an M-book is opened.
Defining MATLAB Commands as Input Cells for Notebook the calc zone. The section break indicators include bold, gray brackets to distinguish them from standard Word section breaks. You can use calc zones to prepare problem sets, making each problem a separate calc zone that can be created and tested on its own. An M-book can contain any number of calc zones. Note 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.
8 Publishing Results 8-47. When you convert an input cell to text, Notebook also converts the corresponding output cell to text.
Evaluating MATLAB Commands with Notebook Evaluating MATLAB Commands with Notebook In this section...
8 Publishing Results 3 Specify the input cell to be evaluated by selecting it with the mouse or by placing the cursor in it. Then 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. For example: This is a sample M-book.
Evaluating MATLAB Commands with Notebook Note Text or numeric output always comes first, regardless of the order of the commands in the group. The illustration shows a cell group and the figure created when you evaluate the cell group.
8 Publishing Results 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 Select Notebook > Evaluate Cell or press Ctrl+Enter. Notebook evaluates each input cell in the selection, inserting new output cells or replacing existing ones. Evaluating a Calc Zone with Notebook 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 MATLAB Commands with Notebook The Notebook Options dialog box opens. 2 Select the Stop evaluating on error check box and click OK. Using a Loop to Evaluate Input Cells Repeatedly with Notebook To evaluate a sequence of MATLAB commands repeatedly, 1 Use the mouse to select the input cells, including any text or output cells located between them. 2 Select Notebook > Evaluate Loop or press Alt+L. Notebook displays the Evaluate Loop dialog box.
8 Publishing Results Converting Output Cells to Text with Notebook 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. Note Undefining an output cell does not affect the associated input cell.
Printing and Formatting an M-Book Printing and Formatting an M-Book In this section...
8 Publishing Results shades of gray. To print these cells using black type, you need to modify the color of the Input, Output, AutoInit, and Error styles in the M-book template. The table below describes the default styles used by Notebook. If you modify styles, you can use the information in the tables below to help you return the styles to their original settings. For general information about using styles in Word documents, see the Word documentation.
Printing and Formatting an M-Book Note Changes you make using the Notebook Options dialog box take effect for output generated after you click OK. To affect existing input or output cells, you must reevaluate the cells. Controlling Numeric Output Format for Notebook To change how Notebook displays numeric output, 1 Select Notebook > Notebook Options. 2 In the Notebook Options dialog box, select a format from the Numeric Format list.
8 Publishing Results 1 Select Notebook > Notebook Options. 2 In the Notebook Options dialog box, clear the Embed Figures in M-book check box. 3 Click OK. Note Embedded figures do not include Handle Graphics objects generated by the uicontrol and uimenu functions. Notebook determines whether to embed a figure in the M-book by examining the value of the figure object’s Visible property. If the value of the property is off, Notebook embeds the figure.
Printing and Formatting an M-Book To allow graphic output for a cell, repeat the procedure. Notebook removes the (no graph) marker and allows graphic output from the cell. Note Toggle Graph Output for Cell overrides the Embed Figures in M-book option, if that option is set. Sizing Graphic Output in Notebook To set the default size of embedded graphics in an M-book, 1 Select Notebook > Notebook Options.
8 Publishing Results Adding White Space Around Graphic Output in Notebook You can add white space around an embedded figure by moving the boundaries of a graphic outward. Select the graphic, then hold down the Shift key and drag a sizing handle away from the graphic.
Configuring Notebook Configuring Notebook After you install Notebook but before you begin using it, you must configure it. (Notebook is installed as part of the MATLAB installation process on Windows platforms. For more information, see the MATLAB installation documentation for your platform.) Before configuring Notebook, you must specify that Word can use the Notebook macros.
8 Publishing Results Notebook Feature Reference In this section...
Notebook Feature Reference Define Autoinit Cell Define AutoInit Cell creates an autoinit cell by converting the current paragraph, selected text, or input cell. An autoinit cell is an input cell that is automatically evaluated whenever you open an M-book. Result If you select this feature while the cursor is in a paragraph of text, Notebook converts the entire paragraph to an autoinit cell. If you select this feature while text is selected, Notebook converts the text to an autoinit cell.
8 Publishing Results Define Input Cell Define Input Cell creates an input cell by converting the current paragraph, selected text, or autoinit cell. An input cell contains a MATLAB command. Result If you select this feature while the cursor is in a paragraph of text, Notebook converts the entire paragraph to an input cell. If you select this feature while text is selected, Notebook converts the text to an input cell.
Notebook Feature Reference See Also For more information, see “Evaluating a Calc Zone with Notebook” on page 8-44. Evaluate Cell Evaluate Cell sends the current input cell or cell group to MATLAB to be evaluated. An input cell contains a MATLAB command. A cell group is a single, multiline input cell that contains more than one MATLAB command. Notebook displays the output or an error message in an output cell.
8 Publishing Results See Also For more information, see “Evaluating MATLAB Commands with Notebook” on page 8-41. For information about evaluating the entire M-book, see “Evaluating an Entire M-Book” on page 8-44. Evaluate Loop Evaluate Loop evaluates the selected input cells repeatedly. For more information, see “Using a Loop to Evaluate Input Cells Repeatedly with Notebook” on page 8-45. Evaluate M-Book Evaluate M-book evaluates the entire M-book, sending all input cells to MATLAB to be evaluated.
Notebook Feature Reference Result If you include text in the selection, Notebook moves it after the cell group. However, if text precedes the first input cell in the group, the text will remain before the group. If you include output cells in the selection, Notebook deletes them. If you select all or part of an output cell before selecting this feature, Notebook includes its input cell in the cell group.
8 Publishing Results Purge Selected Output Cells Purge Selected Output Cells deletes all output cells from the current selection. See Also For more information, see “Deleting Output Cells with Notebook” on page 8-46. Toggle Graph Output for Cell Toggle Graph Output for Cell suppresses or allows graphic output from an input cell. If an input or autoinit cell generates figure output that you want to suppress, place the cursor in the input cell and choose this feature.
Notebook Feature Reference See Also For information about the Normal style, see “Modifying Styles in the M-Book Template” on page 8-47. For information about deleting output cells, see the description of the “Purge Selected Output Cells” on page 8-60. Ungroup Cells Ungroup Cells converts the current cell group into a sequence of individual input cells or autoinit cells. If the cell group is an input cell, Notebook converts the cell group to input cells.
8 8-62 Publishing Results
9 Source Control Interface The source control interface provides access to your source control system from MATLAB. Source control systems, also known as version control, revision control, configuration management, and file management systems, are platform dependent — the topics for the Windows platforms appear first, followed by the topics for the UNIX platforms. Source Control Interface on Windows (p. 9-3) Overview of the ways you can use the source control interface on Windows platforms.
9 9-2 Source Control Interface Troubleshooting Source Control Problems on Windows (p. 9-24) Solutions to some common source control problems. Source Control Interface on UNIX (p. 9-26) Overview of the ways you can use the source control interface on UNIX platforms. Specifying the Source Control System on UNIX (p. 9-27) Specify the source control system using MATLAB, list the currently selected source control system using the cmopts function, set a view and check out a directory with ClearCase.
Source Control Interface on Windows Source Control Interface on Windows If you use source control systems to manage your files, you can interface with the systems to perform source control actions from within MATLAB, Simulink, and Stateflow®. Use menu items in MATLAB, Simulink, or Stateflow, or run functions in the MATLAB Command Window to interface with your source control systems.
9 Source Control Interface Setting Up the Source Control Interface on Windows In this section... “Create Projects in Source Control System” on page 9-4 “Specify Source Control System in MATLAB” on page 9-6 “Register Source Control Project with MATLAB” on page 9-7 “Add Files to Source Control” on page 9-9 Create Projects in Source Control System In your source control system, create the projects that your directories and files will be associated with.
Setting Up the Source Control Interface on Windows The following illustration shows the example project in the source control system. To set the working directory in Microsoft Visual SourceSafe for this example, select my_thesis_files, right-click, select Set Working Folder from the context menu, and specify D:\my_thesis_files in the resulting dialog box.
9 Source Control Interface Specify Source Control System in MATLAB In MATLAB, specify the source control system you want to access. Select File > Preferences > General > Source Control. The currently selected system is shown in the Preferences dialog box. The list includes all installed source control systems that support the Microsoft Common Source Control standard. Select the source control system you want to interface with and click OK.
Setting Up the Source Control Interface on Windows MATLAB remembers preferences between sessions, so you only need to perform this action again when you want to access a different source control system. Function Alternative A function alternative to select a source control system is not available, but you can list all available source control systems using verctrl with the all_systems argument. Use cmopts to display the name of the currently selected source control system.
9 Source Control Interface The following example shows Microsoft Visual SourceSafe. 3 In the resulting Name_of_Source_Control_System Login dialog box, provide the username and password you use to access your source control system, and click OK.
Setting Up the Source Control Interface on Windows 4 In the resulting Choose project from Name_of_Source_Control_System dialog box, select the source control system project to associate with the directory and click OK. This example shows my_thesis_files. The selected file, its directory, and all files in the directory, are associated with the source control system project you selected. For the example, MATLAB associates all files in D:\my_thesis_files with the source control project my_thesis_files.
9 Source Control Interface 2 Right-click, and from the context menu, select Source Control > Add to Source Control. 3 The resulting Add to source control dialog box lists files you selected to add. You can add text in the Comments field. If you expect to use the files soon, select the Keep checked out check box (which is selected by default). Click OK. If you try to add an unsaved file, the file is automatically saved upon adding.
Checking Files Into and Out of Source Control from MATLAB on Windows Checking Files Into and Out of Source Control from MATLAB on Windows In this section... “Check Files Into Source Control” on page 9-11 “Check Files Out of Source Control” on page 9-12 “Undoing the Checkout” on page 9-13 Before checking files into and out of your source control system from MATLAB, be sure to set up your system for use with MATLAB as described in “Setting Up the Source Control Interface on Windows” on page 9-4.
9 Source Control Interface Check Files Out of Source Control From MATLAB, to check out the files you want to modify, perform these steps: 1 In the Current Directory browser, select the files to check out. 2 Right-click, and from the context menu, select Source Control > Check Out. 3 The resulting Check out file(s) dialog box lists files you selected to check out. Enter comment text in the Comments field, which appears if your source control system supports comments on checkout. Click OK.
Checking Files Into and Out of Source Control from MATLAB on Windows Function Alternative The function alternative is verctrl with the checkout argument. Undoing the Checkout You can undo the checkout for files. The files remain checked in, and do not have any of the changes you made since you last checked them out. To save any changes you have made since checking out a particular file select File > Save As, and supply a different filename before you undo the checkout.
9 Source Control Interface Additional Source Control Actions on Windows In this section...
Additional Source Control Actions on Windows 2 Right-click, and from the context menu, select Source Control > Get Latest Version. The MATLAB Get latest version dialog box opens, listing the files or directories you selected. 3 Click OK. You can now open the file to view it, run the file, or check out the file for editing. Function Alternative The function alternative is verctrl with the get argument.
9 Source Control Interface 3 Click OK. Function Alternative The function alternative is verctrl with the remove argument. Showing File History To show the history of a file in the source control system, follow these steps: 1 In the MATLAB Current Directory browser, select the file for which you want to view the history. 2 Right-click, and from the context menu, select Source Control > History.
Additional Source Control Actions on Windows A dialog box, which is specific to your source control system, opens. For Microsoft Visual SourceSafe, the History Options dialog box opens, as shown in the following example illustration. 3 Complete the dialog box to specify the range of history you want for the selected file and click OK. For example, enter my_name for User.
9 Source Control Interface The history presented depends on your source control system. For Microsoft Visual SourceSafe, the History dialog box opens for that file, showing the file’s history in the source control system. Function Alternative The function alternative is verctrl with the history argument.
Additional Source Control Actions on Windows 2 Right-click, and from the context menu, select Source Control > Differences. A dialog box, which is specific to your source control system, opens. For Microsoft Visual SourceSafe, the Difference Options dialog box opens. 3 Review the default entries in the dialog box, make any needed changes, and click OK. The following example is for Microsoft Visual Source Safe. The method of presenting differences depends on your source control system.
9 Source Control Interface Function Alternative The function alternative is verctrl with the showdiff or isdiff argument. Viewing Source Control Properties of a File To view the source control properties of a file, follow these steps: 1 In the MATLAB Current Directory browser, select the file for which you want to view properties. 2 Right-click, and from the context menu, select Source Control > Properties.
Additional Source Control Actions on Windows A dialog box, which is specific to your source control system, opens. The following example shows the Microsoft Visual SourceSafe properties dialog box. Function Alternative The function alternative is verctrl with the properties argument. Starting the Source Control System All the MATLAB source control actions automatically start the source control system to perform the action, if the source control system is not already open.
9 Source Control Interface 1 Right-click any directory or file in the MATLAB Current Directory browser 2 From the context menu, select Source Control > Start Source Control System. The interface to your source control system opens, showing the source control project associated with the current directory in MATLAB. The following example shows the Microsoft Visual SourceSafe Explorer interface. Function Alternative The function alternative is verctrl with the runscc argument.
Performing Source Control Actions from the Editor/Debugger, Simulink, or Stateflow on Windows Performing Source Control Actions from the Editor/Debugger, Simulink, or Stateflow on Windows You can create or open a file in the Editor/Debugger, Simulink, or Stateflow and perform most source control actions from their File > Source Control menus, rather than from the Current Directory browser as described in previous sections.
9 Source Control Interface Troubleshooting Source Control Problems on Windows In this section...
Troubleshooting Source Control Problems on Windows installed on a server for a group to use, each machine client can run a setup but is not required to do so. However, some applications that interface with SourceSafe, including MATLAB, require you to run the client setup. Run the client setup, which should resolve the problem. If the problem persists, access source control outside of MATLAB. Restriction Against @ Character Some source control systems, such as Perforce and Synergy, reserve the @ character.
9 Source Control Interface Source Control Interface on UNIX If you use a source control system to manage your files, you can check M-files and Simulink models, and Stateflow charts into and out of the source control system from within MATLAB, Simulink, and Stateflow.
Specifying the Source Control System on UNIX Specifying the Source Control System on UNIX In this section... “MATLAB Alternative” on page 9-27 “Function Alternative” on page 9-28 “Setting a View and Checking Out a Directory with ClearCase on UNIX” on page 9-29 MATLAB Alternative In MATLAB, specify the source control system you want to access. Select File > Preferences > General > Source Control. The currently selected system is shown in the Preferences dialog box. The default selection is None.
9 Source Control Interface MATLAB remembers preferences between sessions, so you only need to perform this action when you want to access a different source control system. Function Alternative A function alternative to select a source control system is not available, but you can list the currently selected source control system by running cmopts.
Specifying the Source Control System on UNIX Setting a View and Checking Out a Directory with ClearCase on UNIX If you use ClearCase on a UNIX platform, perform the following from ClearCase: 1 Set a view. 2 Check out the directory that contains files you want to save, check in, or check out. You can now use the MATLAB, Simulink, or Stateflow source control interfaces to ClearCase.
9 Source Control Interface Checking Files Into the Source Control System on UNIX In this section... “Checking In One or More Files Using the Current Directory Browser” on page 9-30 “Checking In One File Using the Editor/Debugger, Simulink, or Stateflow” on page 9-31 “Function Alternative” on page 9-32 Checking In One or More Files Using the Current Directory Browser 1 From the Current Directory browser, select the file or files to check in.
Checking Files Into the Source Control System on UNIX The files are checked into the source control system. If any file contains unsaved changes when you try to check it in, you will be prompted to and must then save the changes to complete the checkin. An error appears in the Command Window if a file is already checked in. If you did not keep a file checked out and you keep that file open, note that it is a read-only version.
9 Source Control Interface Function Alternative Use checkin to check files into the source control system. The files can be open or closed when you use checkin. The checkin function takes this form: checkin({'file1','file2', ...},'comments','comment_text',... 'option','value') For filen, use the complete path and include the file extension. You must supply the comments argument and a comments string with checkin.
Checking Files Out of the Source Control System on UNIX Checking Files Out of the Source Control System on UNIX In this section... “Checking Out One or More Files Using the Current Directory Browser” on page 9-33 “Checking Out a Single File Using the Editor/Debugger, Simulink, or Stateflow” on page 9-34 “Function Alternative” on page 9-34 Checking Out One or More Files Using the Current Directory Browser 1 In the Current Directory browser, select the file or files to check out.
9 Source Control Interface c To prevent others from checking out the files while you have them checked out, select Lock latest version. To check out read-only versions of the file, clear Lock latest version. 4 Click OK. An error appears in the Command Window if a file is already checked out. After checking out files, make changes to them in MATLAB or another product, and save the files. For example, edit an M-file in the Editor/Debugger.
Checking Files Out of the Source Control System on UNIX For filen, use the complete path and include the file extension. Use the option argument to • Check out a read-only version of the file — set the lock option value to off. • Check out the file even if you already have it checked out — set the force option value to on. • Check out a specific version of the file — use the revision option, and assign the version number to the value argument. The options apply to all files being checked out.
9 Source Control Interface Undoing the Checkout on UNIX In this section...
Undoing the Checkout on UNIX 2 Select File > Source Control > Undo Checkout. MATLAB undoes the checkout. Function Alternative The undocheckout function takes this form: undocheckout({'file1','file2', ...}) Use the complete path for filen and include the file extension. For example, to undo the checkout for the files clock.m and calendar.m, type undocheckout({'\myserver\mymfiles\clock.m',... '\myserver\mymfiles\calendar.
9 9-38 Source Control Interface
Index % Index comment symbol 6-16 create comment 6-17 , after functions 3-30 ; after functions 3-30 ! function 3-9 argument length restrictions 3-10 %% 6-135 {% block comment symbol 6-18 >> prompt in Command Window 3-4 ...
Index in Help browser 4-24 Boolean searching in Help browser 4-21 breaking long lines 3-18 breaking out of a running program 3-9 breakpoints anonymous functions 6-128 blue icon 6-128 clearing (removing) 6-120 clearing, automatically 6-121 conditional 6-126 disabling and enabling 6-119 multiple per line 6-128 running file 6-111 setting 6-107 types 6-107 Bring MATLAB to Front 8-54 browser Help 4-3 Web, in MATLAB 2-55 bugs, reporting to The MathWorks 4-52 built-in editor 6-5 C C/C++ editing files in Editor/D
Index clearing Command Window 3-32 variables 5-8 clicking on multiple items 2-50 clipboard 2-51 closing desktop tools 2-7 M-files 6-64 MATLAB 1-23 code analyzer 6-87 Code check report checking M-files code 7-16 code examples 6-3 code folding in M-files 6-31 code iteration 6-133 code resources 6-3 code samples sample code 6-3 collapsing code in M-files 6-31 Collatz problem 6-104 color general preferences 2-73 indicators for syntax 3-16 printing M-book 8-47 colors Help browser 4-41 in M-files 6-28 preference
Index Editor/Debugger 6-21 compression MAT-files and Fig-Files 2-79 conditional breakpoints 6-126 configuration management See source control system interface 9-1 configuration, desktop 2-6 configurations for M-files in Editor/Debugger 6-67 configuring Notebook 8-53 confirmation dialog boxes preferences 2-81 console mode 3-42 content of M-files, searching 5-49 Contents in Help browser synchronizing preference 4-38 Contents tab in Help browser description 4-10 synchronizing with display 4-12 context menus 2
Index delimiter matching in Editor/Debugger 3-46 delimiter matching preferences 3-46 demos using 4-31 Demos searching 4-16 desktop color preferences 2-70 configuration 2-6 description 2-3 font preferences for 2-62 starting without 1-15 tools closing 2-7 opening 2-5 windows closing 2-7 opening 2-5 desktop layout saving 2-6 desktop, docking 2-7 desktop, grouping tools 2-8 desktop, maximizing tools 2-8 desktop, minimizing tools 2-8 desktop, undocking 2-7 development environment for MATLAB 2-3 diary 3-33 diffe
Index arranging documents 6-11 closing 6-13 closing files 6-64 description 6-7 example 6-104 go to bookmark 6-43 function 6-42 line number 6-42 horizontal lines 6-136 indenting 6-7 modifying values 6-139 navigating 6-42 navigating back and forward 6-44 navigation keys 6-59 opening files 6-9 other text files 6-12 preferences 6-11 rule displayed 6-31 running M-files 6-66 running with unsaved changes 6-125 status bar function 6-31 EDU>> prompt in Command Window 3-4 ellipses (...
Index fatal error 1-24 favorites in Help browser 4-24 feedback to The MathWorks 4-54 Fig-files compatibility 2-79 save options 2-79 file exchange for M-files 4-51 file management system See source control system interface 9-1 filebrowser 5-36 files comparing 6-54 contents, viewing 5-49 copying 5-46 creating in the Current Directory browser 5-44 deleting 5-45 editing M-files 6-7 log 1-14 MATLAB related, listing 5-38 naming 5-24 opening 5-47 operations in MATLAB 5-35 renaming 5-45 running 5-49 viewing conten
Index embedding in M-book 8-49 in M-books 8-49 within cell 8-14 gray background color in desktop 2-73 gray breakpoint icons 6-109 gray lines in Editor/Debugger 6-136 green indicator in Editor/Debugger 6-87 Group Cells 8-58 grouping tools in desktop 2-8 H HDF preference when saving 2-79 headings within cell 8-12 help 4-46 functions 4-44 in Command Window 4-46 M-file description 5-55 M-files 4-8 pop-up 4-49 help browser copying information from 4-29 running examples from 4-29 Help browser 4-3 color preferen
Index Help browser 4-13 results 4-15 tips 4-15 initiation (init) file for MATLAB 1-12 inline links within cell 8-22 input to MATLAB in Command Window 3-3 input cells controlling evaluation 8-44 controlling graphic output 8-50 converting autoinit cell to 8-56 converting text to 8-56 converting to autoinit cell 8-55 converting to cell groups 8-61 converting to text 8-39 defining in M-books 8-36 evaluating 8-41 evaluating cell groups 8-42 evaluating in loop 8-45 maintaining consistency 8-34 timing out during
Index line wrapping 3-42 lines (gray) Editor/Debugger 6-136 links Command Window 3-13 in Help browser 4-28 lists within cell 8-14 load 5-7 locking files on checkout 9-33 log automatic 1-14 file 1-14 session 3-33 statements 3-49 logfile startup option 1-14 login remote on Macintosh 1-7 long lines 3-18 lookfor 5-54 looping to evaluate input cells 8-45 lowercase usage in MATLAB 3-15 M M-books creating 8-27 data consistency 8-35 data integrity 8-34 entering text and commands 8-34 evaluating all input cells 8-
Index MAT-files compatibility 2-79 compression options 2-79 creating 5-5 defined 5-5 loading 5-7 preferences 2-79 starting MATLAB from 1-2 view without loading 5-42 matched delimiters preferences 3-46 matching parentheses in Editor/Debugger 3-46 Mathtools.net 4-53 MATLAB commands, executing in a Word document 8-41 files, listing 5-38 path 5-23 quitting 1-23 confirmation 1-23 matlab directory 1-8 MATLAB functions running by hyperlink 3-14 matlab.mat 5-6 matlabrc.
Index output 3-31 preferences 3-41 O %#ok indicator to suppress M-Lint message 7-17 open 5-48 opening files Current Directory browser 5-47 openvar 5-14 operating system commands 3-9 operators searching for 4-22 optimizing performance of M-files 7-27 options shutdown 1-24 startup 1-12 orange underline in M-file 6-92 output display format 3-31 hidden 3-30 hiding 3-30 in Command Window 3-3 paging 3-30 spaces per tab 3-43 spacing of 3-42 suppressing 3-30 output cells converting to text 8-46 purging 8-46 Outp
Index Command History window contents 3-57 Command Window contents 3-33 documentation 4-42 help 4-42 M-files 6-64 printing an M-book cell markers 8-47 color 8-47 defaults 8-47 problems, reporting to The MathWorks 4-52 product filter in Help browser preference 4-37 product version 2-58 profile 7-42 example 7-43 profiling 7-27 programs running from MATLAB 3-9 stopping while running 3-9 prompt in Command Window 3-3 when debugging 6-111 properties source control on Windows platforms 9-20 tab completion Command
Index S save function 5-6 saving automatically in Editor/Debugger 6-63 M-files 6-62 MAT-files preferences 2-79 workspace upon quitting 1-24 screen reader 2-87 script for startup 1-12 scroll buffer for Command Window 3-42 scrolling in Command Window 3-30 search path 5-23 default 5-23 problems and recovering 5-33 saving for future sessions 5-30 searching for M-files 5-49 Help browser 4-16 Boolean 4-21 exact phrase (" ") 4-21 results 4-18 text in page 4-28 wildcard (*) or partial word 4-21 M-file content acr
Index source control on UNIX platforms getting files 9-33 locking files 9-33 source control system interface 9-1 UNIX platforms 9-26 preferences 9-27 selecting system 9-27 supported systems 9-26 Windows platforms adding files 9-9 preferences 9-6 selecting system 9-6 supported systems 9-3 source control system interface on UNIX platforms checking in files 9-30 checking out files 9-33 configuring ClearCase source control system 9-29 undoing file check-out 9-36 source control system interface on Windows platf
Index styles in M-book modifying 8-47 subfunction displayed in Editor/Debugger status bar 6-31 subfunctions going to in M-file 6-42 suggestions to The MathWorks 4-54 support technical 4-52 suppressing output 3-30 switches for startup 1-12 symbols searching for 4-22 syntax color indicators 2-73 color preferences in MATLAB 2-70 coloring and indenting 3-16 errors 6-84 highlighting 6-28 system environment variables 3-10 system path for UNIX 3-11 system requirements MATLAB 1-1 T tab indenting in Editor/Debugge
Index U UNC (Universal Naming Convention) pathname 7-3 uncomment 6-16 Undefine Cells 8-60 undo in desktop 2-51 in Editor 6-15 undocking tools from desktop 2-7 undoing file check-out on UNIX platforms 9-36 on Windows platforms 9-13 Ungroup Cells 8-61 Unicode preference when saving 2-79 UNIX system path 3-11 updates to products 2-56 uppercase usage in MATLAB 3-15 utilities running from MATLAB 3-9 V validating M-files 7-16 values examining 6-114 variables deleting or clearing 5-8 displaying values of 5-14 ed
Index opening 5-7 protecting integrity 8-34 saving 5-5 tool 5-2 viewing 5-3 viewing during execution 6-114 Workspace browser description 5-2 plotting variables from 5-9 preferences 5-8 Index-18 wrapping lines in Command Window 3-42 long statements 3-18 Y yellow highlighting in M-file current cell 6-136 datatip 6-115 M-Lint message 6-92