Desktop Tools and Development Environment: Matlab
Desktop Tools and Development Environment: Matlab
R2012b
How to Contact MathWorks
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
www.mathworks.com/contact_TS.html Technical Support
508-647-7000 (Phone)
508-647-7001 (Fax)
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
June 2004 First printing New for MATLAB 7.0 (Release 14). Formerly part of
Using MATLAB.
October 2004 Online only Revised for MATLAB 7.0.1 (Release 14SP1)
March 2005 Online only Revised for MATLAB 7.0.4 (Release 14SP2)
March 2005 Second printing Revised for MATLAB 7.0.4 (Release 14SP2)
June 2005 Third printing Minor revision for MATLAB 7.0.4 (Release 14SP2)
September 2005 Online only Revised for MATLAB 7.1 (Release 14SP3)
March 2006 Online only Revised for MATLAB 7.2 (Release 2006a)
September 2006 Online only Revised for MATLAB 7.3 (Release 2006b)
March 2007 Online only Revised for MATLAB 7.4 (Release 2007a)
September 2007 Online only Revised for MATLAB 7.5 (Release 2007b)
March 2008 Online only Revised for MATLAB 7.6 (Release 2008a)
October 2008 Online only Revised for MATLAB 7.7 (Release 2008b)
March 2009 Online only Revised for MATLAB 7.8 (Release 2009a)
September 2009 Online only Revised for MATLAB 7.9 (Release 2009b)
March 2010 Online only Revised for MATLAB 7.10 (Release 2010a)
September 2010 Online only Revised for MATLAB Version 7.11 (Release 2010b)
April 2011 Online only Revised for MATLAB Version 7.12 (Release 2011a)
September 2011 Online only Revised for MATLAB Version 7.13 (Release 2011b)
March 2012 Online only Revised for MATLAB Version 7.14 (Release 2012a)
September 2012 Online only Revised for MATLAB Version 8.0 (Release 2012b)
Contents
Desktop
2
Adjust Desktop Appearance . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
v
Color Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7
Access Frequently Used Features . . . . . . . . . . . . . . . . . . . . 2-10
Optimize Desktop Layout for Limited Screen Space . . . . . 2-11
Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-52
vi Contents
Set Preferences for MATLAB . . . . . . . . . . . . . . . . . . . . . . . . 2-52
Where MATLAB Stores Preferences . . . . . . . . . . . . . . . . . . 2-53
Preferences Folder and Files MATLAB Uses When Multiple
MATLAB Releases Are Installed . . . . . . . . . . . . . . . . . . . 2-54
General Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-55
MAT-Files Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-56
Confirmation Dialogs Preferences . . . . . . . . . . . . . . . . . . . . 2-57
Source Control Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . 2-59
Java Heap Memory Preferences . . . . . . . . . . . . . . . . . . . . . . 2-59
Keyboard Shortcuts Preferences . . . . . . . . . . . . . . . . . . . . . 2-60
Fonts Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-62
Fonts Custom Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . 2-63
Colors Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-64
Colors Programming Tools Preferences . . . . . . . . . . . . . . . . 2-65
Toolbars Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-66
Web Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-67
Entering Commands
3
Enter Statements in Command Window ............. 3-2
vii
Find Text in the Command Window . . . . . . . . . . . . . . . . . . 3-13
Find Text in the Command History Window . . . . . . . . . . . . 3-15
viii Contents
Contact Technical Support . . . . . . . . . . . . . . . . . . . . . . . . . 4-9
ix
Managing Files in MATLAB
6
Understanding File Locations in MATLAB . . . . . . . . . . . 6-2
Important MATLAB Folders . . . . . . . . . . . . . . . . . . . . . . . . 6-2
Path Names in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5
x Contents
Files and Folders That MATLAB Can Access . . . . . . . . . . . 6-65
How to Make Files Accessible . . . . . . . . . . . . . . . . . . . . . . . 6-65
Determining if MATLAB Can Access a File . . . . . . . . . . . . 6-67
Ensuring MATLAB Uses the File You Want . . . . . . . . . . . . 6-68
Editor Preferences
7
Editor/Debugger Preferences . . . . . . . . . . . . . . . . . . . . . . . 7-2
General Preferences for the Editor/Debugger . . . . . . . . . . . 7-2
Editor/Debugger Display Preferences . . . . . . . . . . . . . . . . . 7-3
Editor/Debugger Tab Preferences . . . . . . . . . . . . . . . . . . . . 7-4
Editor/Debugger Language Preferences . . . . . . . . . . . . . . . 7-5
Editor/Debugger Code Folding Preferences . . . . . . . . . . . . . 7-8
Editor/Debugger Autosave Preferences . . . . . . . . . . . . . . . . 7-9
Internationalization
8
How the MATLAB Process Uses Locale Settings . . . . . . 8-2
Windows Platform-Specific Behavior . . . . . . . . . . . . . . . . . . 8-3
xi
Macintosh Platform-Specific Behavior . . . . . . . . . . . . . . . . . 8-3
Index
xii Contents
1
The way you start the MATLAB® program depends on which platform you
use. The following topics describe how to start up and shut down MATLAB
software on all supported platforms, including information about customizing
startup and shutdown.
After starting MATLAB, the desktop opens. Desktop components that were
open when you last shut down MATLAB will be opened on startup. For
more information, see “Adjust Desktop Appearance” on page 2-2. You can
1-2
Starting and Exiting the MATLAB® Program
specify other startup options, such the current folder upon startup—for more
information, see “Startup Options” on page 1-18 and “Startup Folder for the
MATLAB Program” on page 1-12.
File Result
Extension
.fig Opens file in figure window
.m Opens file in Editor
.mat Opens Import Wizard to load the data into the MATLAB
workspace.
.mdl Opens file in a Simulink® model window
.mex1 Displays icon for MATLAB in Windows Explorer tool
.p Displays icon for MATLAB in Windows Explorer tool
File associations for the Windows Explorer tool do not affect what happens
when you open one of these file types from within MATLAB. MATLAB acts on
the file using the MATLAB tool associated with that file type. For example,
even if your system associates .mat files with the Access™ application, when
1-3
1 Startup and Shutdown
you open a MAT-file from within MATLAB, it opens the Import Wizard to
load the data.
1-4
Starting and Exiting the MATLAB® Program
Note These instructions might not exactly apply to the version of the
Windows operating system you are running on your computer. If you
encounter differences or problems, see your Windows documentation.
5 In the Set Associations window, select a file name extension to view which
program currently opens it by default. In this example, select .mat.
6 To change the default association, click Change Program. This opens the
Open with dialog box which lists other programs that might be recommended
for this file extension. If it’s a file extension associated with MATLAB, such as
.mat, the list includes all the versions of MATLAB you have installed. Select
the version of MATLAB you want to associate with the file extension and click
OK. You create file associations with particular versions of MATLAB.
After associating a file type with MATLAB, you can open other applications
that have the same extension via the context menu. For example, if you want
to open a MAT-file with the Access application, right-click myfile.mat, and
1-5
1 Startup and Shutdown
from the context menu, select Open With. The Access application should
be one of the options.
If you did not set up symbolic links in the installation procedure, you must
enter the full path name, matlabroot/bin/arch, where matlabroot is
the name of the folder in which you installed MATLAB and arch is an
architecture-specific subfolder, such as glnxa64.
After starting MATLAB, the desktop opens. Desktop components that were
open when you last shut down MATLAB will be opened on startup. For more
information, see “Adjust Desktop Appearance” on page 2-2.
If the DISPLAY environment variable is not set or is invalid, the desktop will
not display. If you have trouble starting MATLAB, see Troubleshooting topics
in the Installation Guide.
You can specify the current folder upon startup as well as other options—for
more information, see “Startup Folder for the MATLAB Program” on page
1-12 and “Startup Options” on page 1-18.
1-6
Starting and Exiting the MATLAB® Program
/Applications/MATLAB_R2012b.app/bin/matlab
After starting MATLAB, the desktop opens. Desktop components that were
open when you last shut down MATLAB will be opened on startup. For more
information, see “Adjust Desktop Appearance” on page 2-2. If the DISPLAY
environment variable is not set or is invalid, the desktop will not display.
You can specify the current folder upon startup as well as other options—for
more information, see “Startup Folder for the MATLAB Program” on page
1-12 and “Startup Options” on page 1-18.
Limitation
On Macintosh platforms, if you run MATLAB remotely, for example using
rlogin, you must run with nodisplay, noawt, and nojvm startup options—for
more information, see “Startup Options” on page 1-18.
1-7
1 Startup and Shutdown
• Click on the left side of the MATLAB desktop title bar and select Close.
• Type quit or exit at the Command Window prompt.
3 Select the Confirm before exiting MATLAB check box and click OK.
MATLAB then displays the following dialog box when you exit.
You can also display your own exit confirmation dialog box using a finish.m
script, as described in the following section.
1-8
Starting and Exiting the MATLAB® Program
Abnormal Termination
To exit and restart without trying to save your work, follow these steps:
1 If you want to view the stack trace for the problem, click Details.
3 Restart MATLAB. If the Error Log Reporter dialog box opens, select the
option to send a report to MathWorks.
1-9
1 Startup and Shutdown
To try to save your work in progress before exiting and restarting MATLAB,
follow these steps:
1 If you want to view the stack trace for the problem, click Details.
The Command Window displays the message Please exit and restart
MATLAB to the left of the prompt, which reminds you to discontinue use.
3 From the Command Window or tool, try to save the workspace and unsaved
files.
4 Exit MATLAB immediately after saving because any further usage would
be unreliable.
5 Restart MATLAB. If the Error Log Reporter dialog box opens, select the
option to send a report to MathWorks.
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-10
Starting and Exiting the MATLAB® Program
It also will not open if you selected the option to never send error reports
the last time the Error Log Reporter opened. If you experience abnormal
termination but do not see the Error Log Reporter on subsequent startups,
you can instead email the reports.
Some of the above suggestions refer to actions you might have needed to
take during the session when MATLAB terminated. If you did not take those
actions, consider regularly performing them to help you recover from any
future abnormal terminations you might experience.
1-11
1 Startup and Shutdown
Accepting the default value for userpath and using it as the startup folder
offers these benefits:
• You can store the MATLAB files you work with in one, appropriately-named
location, such as Documents/MATLAB.
• Your MATLAB files are readily available upon startup, because the current
folder is always the same, for example, Documents/MATLAB.
• You can always run your files because MATLAB automatically adds the
userpath folder to the top of the search path upon startup.
• The first time you run a new version of MATLAB, MATLAB automatically
creates the userpath folder if it does not exist.
• When you upgrade to a newer version of MATLAB, MATLAB automatically
continues to use the same MATLAB folder and your existing files, with all
of its other benefits.
1-12
Startup Folder for the MATLAB® Program
• The default userpath also utilizes the benefits provided by the standard
location in the Windows and Macintosh environments for storing personal
files. Files in the Documents/MATLAB folder (or My Documents/MATLAB
on Windows platforms other than Windows Vista) are available to
you when you use other machines. Because each user has their own
Documents/MATLAB folder, other users, even those using your machine,
cannot access files in your Documents/MATLAB folder.
To view the userpath value, run the userpath function. To specify a location
other than the default for userpath, or if you do not want to take advantage
of userpath, make changes with the userpath function.
There are other ways to change the startup folder as well as the folders on
your search path. For more information, see “Changing the Startup Folder” on
page 1-14 and “Viewing Files and Folders on the Search Path” on page 6-73.
1-13
1 Startup and Shutdown
You can specify that the userpath be the startup folder by setting the
value of the environment variable MATLAB_USE_USERPATH to 1 prior to
startup. By default, userpath is userhome/Documents/MATLAB, and MATLAB
automatically adds the userpath folder to the top of the search path upon
startup. To specify a different folder for userpath, and for other options,
use the MATLAB userpath function.
When you start MATLAB in a shell, the default startup folder is the folder
from which you started MATLAB.
1-14
Startup Folder for the MATLAB® Program
• “Changing the Startup Folder Via the userpath Function” on page 1-15
• “Changing the Startup Folder Using the Shortcut — Windows Platforms
Only” on page 1-15
• “Changing the Startup Folder Using the startup.m File” on page 1-17
1 Right-click the shortcut icon for MATLAB and select Properties from
the context menu.
The Properties dialog box for MATLAB opens to the Shortcut pane.
In the Start in field, specify the full path to the folder in which you want
MATLAB to start, and click OK.
1-15
1 Startup and Shutdown
Click OK.
The next time you start MATLAB using that shortcut icon, the current folder
will be the one you specified in step 2.
1-16
Startup Folder for the MATLAB® Program
You can make multiple shortcuts to start MATLAB, each with its own startup
folder, and with each startup folder having different startup options.
1-17
1 Startup and Shutdown
Startup Options
In this section...
“Specifying MATLAB Startup Options” on page 1-18
“Commonly Used Startup Options” on page 1-20
“Passing Perl Variables on Startup” on page 1-21
“Startup and Calling Java Software from the MATLAB Program” on page
1-22
matlab -nosplash
On Windows platforms, you can precede a startup option with either a hyphen
(-) or a slash (/). For example, -nosplash and /nosplash are equivalent.
On all platforms, you can also specify startup options using a MATLAB
startup file—see “Specifying Startup Options in the MATLAB Startup File”
on page 1-19
1-18
Startup Options
1 Right-click the shortcut icon for MATLAB and select Properties from
the context menu. The Properties dialog box for MATLAB opens to the
Shortcut pane.
2 In the Target field, after the target path for matlab.exe, add the startup
option, and click OK. For example, adding -r "filename" runs the
MATLAB code file filename after startup.
This example instructs MATLAB to automatically run the file results after
startup, where results.m is in the startup folder or on the search path for
MATLAB. The statement in the Target field might appear as
Separate multiple options with spaces. This example starts MATLAB without
displaying the splash screen, and then runs the MATLAB code file results:
1-19
1 Startup and Shutdown
The file startup.m is for you to specify startup options. For example, you can
modify the default search path, predefine variables in your workspace, or
define defaults for Handle Graphics® objects. Use the following statements in
a startup.m file to add the specified folder, /home/username/mytools, to the
search path, and to change the current folder to mytools upon startup.
addpath /home/username/mytools
cd /home/username/mytools
Place the startup.m file in the default or current startup folder, which is
where MATLAB first looks for it. For more information, see “Startup Folder
for the MATLAB Program” on page 1-12.
1-20
Startup Options
function test(x)
matlab -r "test(10)"
matlab -r "test(10)"
1-21
1 Startup and Shutdown
This command starts MATLAB and runs test with the input argument 10.
#!/usr/local/bin/perl
$val = 10;
system('matlab -r "test(' . ${val} . ')"');
For more information, see the matlab (Windows) or matlab (UNIX) reference
page.
1-22
Toolbox Path Caching in the MATLAB® Program
MATLAB does not use the cache file at startup if you clear the Enable
toolbox path cache check box in File > Preferences > General. Instead,
it creates the cache by reading from the operating system folders, which is
slower than using the cache file.
1-23
1 Startup and Shutdown
We strongly recommend that you save any MATLAB code files you create
and any files provided by MathWorks that you edit in a folder that is
not in the matlabroot/toolbox folder tree. If you keep your files in
matlabroot/toolbox folders, they may be overwritten when you install
a new version of MATLAB.
You need to update the cache so MATLAB will recognize the changes you
made in matlabroot/toolbox folders.
1-24
Toolbox Path Caching in the MATLAB® Program
Function Alternative
To update the cache, use rehash toolbox. To also update the cache file, use
rehash toolboxcache. For more information, see rehash.
1-25
1 Startup and Shutdown
1-26
2
Desktop
Fonts
You can specify the font characteristics (type, style, and size) for:
You can set some font options differently for printing—see “Set Print Options”
on page 2-39.
2 Under Desktop code font select a font type, style, and size from the
drop-down menus.
For font size, you can type a size, including a size not shown as a choice in
the drop-down menu.
2-2
Adjust Desktop Appearance
4 Review the list of tools currently using each font group—Desktop code
font, Desktop text font, and Custom fonts.
If you want to move a tool from one group to another, or if you want to
customize fonts for a particular tool, follow the steps in “Setting Fonts for
Individual Tools” on page 2-3. Otherwise, click OK.
2 Select the tool you want to customize from the Desktop tools list.
The type of font the tool currently uses appears under Font to Use.
2-3
2 Desktop
• Desktop code.
• Desktop text
• Custom (Then, specify the font characteristics.)
4 Click OK.
The font that you select for the Profiler and Comparison Tool also applies to:
For the Profiler and associated tools, you can change the font size, but not
the style (for example, bold or italic).
2-4
Adjust Desktop Appearance
1 On the Home tab, in the Environment section, click Preferences > Fonts.
2 Under Desktop code font, select Times New Roman, Plain, 14 point.
4 Click Apply.
5 Make the Command History window use the desktop text font:
d Click Apply.
2-5
2 Desktop
c Select Arial Narrow and Plain, and then type 11 in the size field.
d Click OK.
Tools Assigned
Font Type Font Characteristics Font
Desktop code Times New Roman® font, Plain, Command Window
14 point
Editor
Desktop text Same as your current system Command History
font, which appears in the
Workspace browser
dimmed fields below the Use
system font check box. Variables editor
Function Browser
Custom Monotype Corporation Arial® Current Folder
Narrow font, Plain, 11 point browser
To resolve this problem, in the Windows Control Panel, find the region and
language options, and then install the supplemental files for East Asian
languages.
2-6
Adjust Desktop Appearance
2 Restart MATLAB.
Color Settings
You can change any of the colors that the desktop uses for text, background,
or denoting links and different types of case-specific highlighting.
Note The colors you specify also apply to the Import Wizard, but do not
apply to the Help display pane or the Web browser.
2-7
2 Desktop
System colors are the text and background colors that your platform (for
example, Microsoft Windows) uses for other applications.
3 Select the colors you want to use from the Text and Background color
palettes.
When you choose a color, the Sample area in the dialog box updates to
show you how it looks.
4 Under Other colors, select the color you want to use for hyperlinks.
5 Click OK.
In the Command Window, only the MATLAB input you type is highlighted.
The output from running MATLAB functions is not highlighted.
2 From the Language drop-down menu, select the language for which you
want to change syntax highlighting colors.
2-8
Adjust Desktop Appearance
• If you set the Language to MATLAB, click the Set syntax colors link, and
then change the colors under MATLAB syntax highlighting colors.
• If you did not set the Language to MATLAB, change the colors under
Syntax highlighting .
5 Click OK.
• Code for which there are warnings, by underlining that code with an orange
wavy line and placing an orange line in the message bar.
• Code for which there are errors, by underlining that code with an red wavy
line and placing a red line in the message bar.
• Code that MATLAB can fix automatically (autofix), by highlighting that
code in tan.
2 Under Code analyzer colors, select the colors you want for warnings,
autofix highlighting, or both.
4 Click Apply.
5 Decide if you want to change the color that the code analyzer uses for errors.
2-9
2 Desktop
6 Click OK.
For more information, see “Automatically Check Code in the Editor — Code
Analyzer”.
You can change the location of the quick access toolbar. On the Home tab,
in the Environment section, click Layout, and then select an option for
the Quick Access Toolbar.
To add a Toolstrip button to the quick access toolbar, right-click the button,
and then select Add to Quick Access Toolbar.
The controls for the selected toolbar appear in the Layout and Controls
sections of the Toolbars Preferences pane.
2-10
Adjust Desktop Appearance
3 In the Controls list, select or clear the check box for controls that you want
to display or remove from the toolbar, respectively.
4 Under Layout, rearrange the order of the controls and separator bars on
the selected toolbar, by doing either of the following:
• Drag the icon for a control or separator bar to another position.
• Select a Layout icon, and then click one of the Layout buttons below
the layout icons.
For instance, to move the MATLAB desktop cut icon to the beginning of
the toolbar, select the Cut icon , and then click .
Desktop Layout
This table shows how you can optimize the MATLAB desktop layout on your
screen.
2-11
2 Desktop
Action Procedure
Minimize or restore the At the upper right corner of the Toolstrip,
MATLAB Toolstrip click or .
Open or hide a tool On the Home tab. in the Environment
section, click Layout. Then, under Show,
select or deselect desktop tools you want
to show or hide.
You also can use a function to open desktop
tools. For example, to open the Editor, use
edit. To open the Profiler, use profile
with the viewer option.
Maximize a tool Do one of the following:
2-12
Adjust Desktop Appearance
Action Procedure
Move undocked tools back to At the upper right of the tool panel, click
the desktop , and then select Dock.
Manage a desktop On the Home tab, in the Environment
arrangement section, click Layout, and then select an
option.
• Save
When youanend
arrangement
a session, MATLAB saves the current desktop arrangement.
The next time you start MATLAB, the desktop appears as you left it.
• Use an arrangement
Note MATLAB
However, tools such as the Help browser, storesand
Web browser, the Variables
arrangements
editor
Rename
• not
do reopenorautomatically,
delete a savedevenyou savewere
if they as XML
openfiles
whenin you
the ended
preferences
the last
arrangement
session. folder
You can use startup options for MATLAB.
to specify Theyou
tools that layout
wantlast used on
to open
startup. For more information, seein “Startup
a sessionOptions”
is MATLABDesktop.xml
on page 1-18. . The
MATLABDesktop.xml file loads when you
start MATLAB and is overwritten when
Document Layout you close MATLAB.
When you open MATLAB documents, they open in the associated tool, such
as the Editor or Variables editor, and a document bar lists all the open
documents. The Editor and Variables editor appear in the position they
occupied when last used. Entries for undocked documents appear on the
Windows task bar, or the equivalent for your platform. Click the task bar
entry for a document to make that document active.
This table shows how to optimize the layout of documents and document
bar within a tool.
Action Procedure
Move or hide document bar On the View tab, in the Document
Bar section, click Bar Position,
and then select an option.
Reorder document names on the Drag a document name to a different
document bar position on the document bar.
To alphabetize names of documents
on the document bar, in the
Document Bar section of the View
tab, select Alphabetize.
2-13
2 Desktop
Action Procedure
Arrange or tile documents In the Editor and Variables editor,
select the View tab. In the Tiles
section, click a tile option.
In a Figure panel, Help browser, or
Web browser, select a tile option, ,
, , or , on the right side of the
toolbar.
Move a tiled document Drag the title bar of the document to
another tile. If you drag it to a tile
that already contains a document,
the document you are dragging
covers up the other document.
Undock a document Right-click the document name in
the document bar, and then select
Undock.
Close and save the document Click .
currently displaying
Close a document in the Editor Click Ctrl + .
without saving
2-14
Define Keyboard Shortcuts
Keyboard Shortcuts
To quickly access desktop features, you can use keyboard shortcuts. Press
Alt to display tooltips on MATLAB Toolstrip buttons, indicating what keys
to press to access those features. For example, pressing Alt followed by H
accesses the Home tab and displays tooltips for the features available on that
tab. You cannot customize these shortcuts.
An action can have multiple keyboard shortcuts. All defined shortcuts work,
but only one appears on the desktop Toolstrip tooltip.
You can:
2-15
2 Desktop
2 Click the down arrow in the Active settings field, and make a selection
from the drop-down list, as summarized in this table.
3 Click Apply.
2-16
Define Keyboard Shortcuts
2 In the Active settings field, click the down arrow, and then select Browse.
3 In the Open dialog box, navigate to the folder containing the settings file.
The settings file you selected in step 4 is now the active settings file for
MATLAB.
Future MATLAB sessions will provide this settings file as a choice in the
Active settings drop-down menu.
2-17
2 Desktop
• Restore the MATLAB default keyboard shortcuts that were in place for
MATLAB Version 7.9 (R2009a) and earlier releases.
• Find and download keyboard shortcuts that others created and uploaded to
File Exchange.
2 In the Active settings field, click the down arrow, and then select Search
File Exchange for Downloadable Shortcut Sets.
4 Search File Exchange for the keyboard shortcut set that you want to use.
When you follow the steps presented so far, File Exchange lists all files
tagged with keyboard shortcuts configurable including:
• MATLAB Desktop R2009a Non-Default Keyboard Shortcut sets
• MATLAB Desktop R2009a Default Keyboard Shortcut sets
For a description, click the file name in the File Summary column of File
Exchange. Click the Back button to return to the list of files.
5 Click the download button next to the file you want to download.
2-18
Define Keyboard Shortcuts
The downloaded .ZIP file appears in the Current Folder Browser. Expand
it to preview its contents.
7 In the Current Folder browser, right-click the downloaded .ZIP file, and
then select Extract.
MATLAB creates a subfolder with the same name as the .ZIP file and
extracts the files from that .ZIP file into the newly created folder.
8 In the Current Folder browser, expand the newly created folder, and then
double-click the settings file you want to use.
2-19
2 Desktop
3 From the drop-down menu, choose the set of keyboard shortcuts to which
you want to compare the current set.
4 The Comparison Tool opens and displays the two keyboard shortcut sets
side-by-side.
• One set displays on the left side of the tool and the other set displays on the
right side of the tool.
• Each column header displays the name of the keyboard shortcut set
contained within the column.
• Highlighting identifies rows that differ:
- Rows that exist in one file, but not the other, appear in green
highlighting.
- Rows that appear in both files, but that differ in content appear in pink
highlighting.
• When multiple desktop tools support the same keyboard shortcut for a
single desktop action, there is a row for each tool. For example, if both the
MATLAB desktop and the Editor support the keyboard shortcut Ctrl+W
for closing a selected window, a column of the Comparison Tool might
appear like this:
• When there are multiple keyboard shortcuts for the same action in a single
tool, there is a row for each keyboard shortcut. For example, if there are
two different keyboard shortcuts in the Editor for applying a code analyzer
autofix, a column of the Comparison Tool might appear like this:
2-20
Define Keyboard Shortcuts
2-21
2 Desktop
2 In the filter field, type the name of the tool for which you want to list
the keyboard shortcuts. For example, type Editor to see the keyboard
shortcuts currently defined for actions you can perform in the Editor.
2-22
Define Keyboard Shortcuts
3 Narrow the list of Action names that the preferences pane displays by
adding a string describing the action. For example, add clear, if you want
to find the keyboard shortcut for clearing selected text in the Editor. Type
a short string to increase the likelihood of the filter returning the action
you seek.
5 View the table labeled Shortcuts for Clear Selection. It indicates that
the Escape key is the current keyboard shortcut for the Clear Selection
action in the Editor.
2-23
2 Desktop
2 In the Active settings field, choose the file that contains the set of
keyboard shortcuts that you want to customize.
Typically, the first time you modify keyboard shortcuts, you begin with
the default settings for your platform. For details, see “Choose a Set of
Keyboard Shortcuts” on page 2-16.
3 Under Action name, select the action for which you want to define or
modify a keyboard shortcut. An action is the operation for which you want
to customize the shortcut, such as Clear Command History.
For tips on finding the action you want, see “Filter Keyboard Shortcut
Actions” on page 2-27.
2-24
Define Keyboard Shortcuts
5 Type the shortcut that you want to use for the action you selected in Step 3.
Alternatively, you can choose a shortcut from the drop-down menu.
For details, see “Specify Keystrokes for a Keyboard Shortcut” on page 2-28.
6 Assign the shortcut to the tool or tools with which you want to use it. For
example, in the Tools with shortcut column:
a Click the down arrow for the list of desktop tools to which you can
assign a shortcut. Not all actions are available with all desktop tools.
b Select a check box to assign the shortcut to a tool. Clear a check box
to remove it.
8 Click Apply.
2-25
2 Desktop
3 Click OK.
Note Undoing modifications reverts all keyboard shortcuts changes that you
made to the set. You cannot undo modifications on a shortcut-by-shortcut
basis.
• Save changes you make to a default settings file, such as the Windows
default set, to a new set.
MATLAB preserves changes you make to the default sets across sessions.
However, if you undo modifications to a default keyboard shortcut set (as
described in “Restore Default Keyboard Shortcut Sets” on page 2-26) you
lose all changes, unless you first save them to a new set.
• Copy the keyboard shortcuts settings file to another system running
MATLAB and use it there.
• Overwrite a settings file that you previously saved.
You cannot overwrite the default settings files that install with MATLAB.
MATLAB saves modifications that you make to a default set using the
2-26
Define Keyboard Shortcuts
name of the default set appended with the text (modified). For instance,
Windows default (modified).
• Share a keyboard shortcuts settings file with others.
For example, you can submit your file to the File Exchange repository.
Click this link to go directly to the page where you can submit your file:
MATLAB Central File Exchange — Submit New File.
1 Open the Keyboard Shortcuts Preferences dialog box. On the Home tab, in
the Environment section, click Preferences > Keyboard > Shortcuts.
3 In the Save dialog box, navigate to the folder where you want to save the
file, specify the file name, and then click Save.
MATLAB saves the file as an .xml file in the folder that you specified.
2-27
2 Desktop
MATLAB displays only the action names that have the shortcut you
specify. Be aware of the following:
– You can enter most keyboard shortcuts by either pressing keystrokes
or typing the key names.
For example, to enter Ctrl+S, use the keystroke (by pressing the
Ctrl key and the S key). Or, type Ctrl+S character by character
(C-t-r-l-+-Y).
– If using keystrokes for a keyboard shortcut does not work, try typing
the characters instead. You must type some keyboard shortcuts
character by character, such as shortcuts including the Tab,
Backspace, or Delete keys.
– Type numpad to refer to the number pad that is on the far right of
some keyboards.
– Type Up or Down to refer to the Up arrow or Down arrow keypad
keys, respectively.
a Hover the mouse pointer over the Action name. For example, Remove
Next Word.
b View the tooltip that appears.
2-28
Define Keyboard Shortcuts
2 Specify the number of keystrokes you want to use for the shortcut:
a Click the down arrow next to the key icon in the Shortcuts field.
b Choose Limit to 1 keystroke, Limit to 2 keystrokes, or Limit
to 3 keystrokes.
• Type the keystrokes, by pressing the keys, not by typing the key names
character by character.
For example, press the Ctrl key and the Y key. Do not type C-t-r-l-+-Y.
• Choose a keystroke, such as the Tab key, by clicking the down arrow next
to the key icon in the Shortcuts field. Then, choose the key name.
The listed keys already have a defined action within dialog boxes. For
example, the Tab key navigates from one field to the next in dialog boxes.
2-29
2 Desktop
2-30
Define Keyboard Shortcuts
• The two actions are associated with different modes of the same tool.
By default, when the MATLAB Editor is in cell mode, Ctrl+Up and
Ctrl+Down move the cursor to the Next and Previous cell, respectively.
When the Editor is not in cell mode, those keyboard shortcuts scroll up and
scroll down, respectively. The shortcuts are in conflict, but the behavior
probably is expected, for the given MATLAB Editor mode.
Although not evident from the preferences pane, Ctrl+C presents a similar
situation on Windows systems. Ctrl+C is the keyboard shortcut for
interrupting MATLAB execution. However, the default keyboard shortcut
for the copy action is also Ctrl+C. Therefore, if you:
- Select an item, and then press Ctrl+C, it copies the selected item to the
clipboard, — regardless of whether MATLAB is busy.
- Do not select an item and press Ctrl+C, it interrupts MATLAB
execution.
If you change the default keyboard shortcut for the copy action from
Ctrl+C to another keystroke, then Ctrl+C interrupts MATLAB execution,
regardless of whether you have selected an item.
2-31
2 Desktop
3 Scroll through the Action name list, and select Add to Favorites.
5 In the Shortcut field, click the down arrow, and then change Limit to 1
keystroke to Limit to 2 keystrokes.
Notice that the All possible conflicts table is empty, which indicates that no
other desktop action is currently using this combination of keystrokes.
7 Click Apply.
Notice that:
• The Add to Favorites dialog box opens when you press Ctrl+S, Alt+V
in the Help browser.
• Ctrl+S, Alt+V appears next to Add to Favorites when you click the
Favorites menu in the Help browser.
2-32
Define Keyboard Shortcuts
This example changes the keyboard shortcut for Decrease Indent in the
MATLAB Editor from Ctrl+[ to Ctrl+Backspace:.
The first time you press the key combination, it deletes Ctrl+[. The second
time you press it, Ctrl+Backspace appears in the field.
2-33
2 Desktop
7 Click Apply.
5 In the next table, under Shortcuts for Autofix Message, select the row
containing Alt+Enter.
7 Click Apply.
2-34
Define Keyboard Shortcuts
2 Under Active settings, choose the set of keyboard shortcuts that you
want to delete.
3 Click the Actions button and choose Delete filename, where filename
is the name of a keyboard shortcut set you previously saved or copied to
your system.
For information on deleting a single keyboard shortcut from a set that you
want to keep, see “Deleting a Keyboard Shortcut” on page 2-34.
I:\my_matlab_files\active_settings_files\new_settings.xml
2-35
2 Desktop
3 In the Active settings field, click the down arrow, and then click Browse.
4 In the Open dialog box, navigate to the folder where you copied the settings
file.
6 In the Keyboard Shortcuts preferences pane, click Apply. The settings file
you specified is now the active settings file for MATLAB.
• “Tools for Which You Cannot Customize Keyboard Shortcuts” on page 2-36
• “Actions for Which You Cannot Customize Keyboard Shortcuts” on page
2-36
2-36
Define Keyboard Shortcuts
2-37
2 Desktop
2-38
Set Print Options
MATLAB provides special page setup options for printing from the Command
Window and Editor. The setup options are essentially the same for both tools,
with minor variations. This section covers their use:
1 In the tool you want to print from, for example, the Command Window, select
Page Setup.
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.
4 After specifying the options, select Print in the tool you want to print from,
for example, the Command Window.
The contents from the tool print, using the options you specified in Page Setup.
2-39
2 Desktop
• 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. Options
are black and white text (that is, no highlighting), colored text (for use with
a color printer), or styled text. For styled text, keywords appear in bold,
comments appear in italics, and all other text appears in the normal style.
Only keywords and comments you input in the Command Window are
highlighted; output is not highlighted.
1 From Choose font, select the element, either Body or Header, where Body
text is everything except the Header.
For example, if you access this dialog box while using the Command Window,
you can select Use Command Window font for Body text. The printed text
matches the Command Window font.
If you did not select Print header on the Layout pane, you do not need to
specify the Header font.
2-40
Set Print Options
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.
Tip You can change the font that a desktop tool uses. On the Home tab, in
the Environment section, click Preferences > Fonts > Custom.
2-41
2 Desktop
2-42
Web Browsers and MATLAB®
2-43
2 Desktop
System Browser
The system browser that MATLAB uses depends on your platform:
To display a Web page or any file type in the MATLAB Web browser:
1 On the Home tab, in the Environment section, click Preferences > Web.
2 Select the Use a proxy server to connect to the Internet check box.
2-44
Web Browsers and MATLAB®
Examples of acceptable formats for the host are: 172.16.10.8 and ourproxy.
For the port, enter an integer only, such as 22. If you do not know the values
for your proxy server, ask your system or network administrator for the
information.
If your proxy server requires a user name and password, select the Use a
proxy with authentication check box. Then enter your proxy user name
and password.
4 Ensure that your settings work by clicking the Test connection button.
• If MATLAB can access the Internet, Success! appears next to the button.
• If MATLAB cannot access the Internet, Failed! appears next to the button.
Correct the values you entered and try again. If you still cannot connect, try
using the values you used when you authenticated your MATLAB license.
1 On the Home tab, in the Environment section, click Preferences > Web.
2 Under System Web browser, in the Command field, specify the system
command to open the browser, for example, opera, which opens the Opera
Web browser.
2-45
2 Desktop
3 Add options for opening your system browser in the Options field. For
example, geometry 1064x860 specifies the size of the window for Opera.
4 Click OK.
2-46
License Management and Software Updates
2 Select a Licensing option. The following table describes the Licensing options.
Depending on your license type, your system might not include all of these
options.
Option Description
Update Displays a list of all your MathWorks licenses on this
Current computer, with their current status. When you select a
Licenses license and click Update Selected License, MATLAB
contacts MathWorks to retrieve the most current version
of the License File for the license. The update process
2-47
2 Desktop
Option Description
2-48
License Management and Software Updates
2 Select Help > Check for Updates. The Check for Updates dialog box
displays.
3 From the Select View list, choose to view the latest version numbers for all
MathWorks products installed on your system, or all MathWorks products.
4 Click any column heading to sort or reverse the sort order by that column.
5 Use the What’s New column to access the release notes for a product.
Release notes document new features and changes, bug reports, and
compatibility considerations.
7 Click Close.
2-49
2 Desktop
To view the contents of the MATLAB root folder in the Mac Finder, right-click
the MATLAB application bundle, and then select Show Package Contents
from the context menu.
To view the content of the MATLAB root folder from within MATLAB:
2-50
Macintosh Platform Conventions
4 Press Go.
To open a file with a MATLAB command, such as edit, specify the full path of
the MATLAB root folder. For example:
edit(fullfile(matlabroot,'/toolbox/matlab/demos/lotka.m'))
2-51
2 Desktop
Preferences
In this section...
“Set Preferences for MATLAB” on page 2-52
“Where MATLAB Stores Preferences” on page 2-53
“Preferences Folder and Files MATLAB Uses When Multiple MATLAB
Releases Are Installed” on page 2-54
“General Preferences” on page 2-55
“MAT-Files Preferences” on page 2-56
“Confirmation Dialogs Preferences” on page 2-57
“Source Control Preferences” on page 2-59
“Java Heap Memory Preferences” on page 2-59
“Keyboard Shortcuts Preferences” on page 2-60
“Fonts Preferences” on page 2-62
“Fonts Custom Preferences” on page 2-63
“Colors Preferences” on page 2-64
“Colors Programming Tools Preferences” on page 2-65
“Toolbars Preferences” on page 2-66
“Web Preferences” on page 2-67
2 From the left pane of the Preferences dialog box, select a tool, product, or an
entry revealed when you click a plus sign (+) preceding a tool or product name.
2-52
Preferences
Function Alternative
Open the Preferences dialog box using the preferences function.
2 In the resulting dialog box, type the path returned by prefdir, and then
press Enter.
The name of the preferences folder, matches the name of the release. For
instance, for MATLAB R2010b, the name of the preferences folder is R2010b.
2-53
2 Desktop
2-54
Preferences
To Use: Do This:
Default preference files for a given Make sure the preferences folder
release of MATLAB for that release exists, but is empty
before starting up that MATLAB
version.
All the preference files from the Ensure that the preferences folder
release of MATLAB immediately exists for that preceding release.
preceding the release you plan to If so, delete the entire preferences
start up folder for the release of MATLAB
you plan to start up.
The release-specific default for just Delete just that file from the
a particular file in the preferences preferences folder for the release of
folder MATLAB you plan to start up.
One file to consider keeping is
history.m. For more information,
see “Command History” on page
3-29.
General Preferences
You can set preferences for toolbox path caching, figure window printing,
and deleting files.
2-55
2 Desktop
Preference Usage
Toolbox path caching Select Enable toolbox path caching
to have MATLAB cache toolbox folder
information across sessions for quicker startup
performance.
Select Enable toolbox path cache
diagnostics to display information about
startup time when you start MATLAB.
Click Update Toolbox Path Cache to
add files to the toolbox folders under the
matlabroot folder. (Use after you use tools not
provided with MATLAB to create MATLAB
files.)
For details, see “Toolbox Path Caching in the
MATLAB Program” on page 1-23.
Figure window printing Select an option to specify how colored lines
and text appear in printed output.
Deleting Files Select an option to specify what MATLAB does
with files you delete using the delete function.
Selecting Delete permanently makes the
delete function run faster.
For details, see “Deleting Files and Folders
Using Functions” on page 6-38.
MAT-Files Preferences
You can set the default MATLAB version for MAT-files and FIG-files.
These preferences apply to both the save function and the Save
menu options. However, the matfile function creates only Version
7.3 MAT-files. On the Home tab, in the Environment section, click
Preferences > General > MAT-Files. Then, adjust preference options as
described in the table below.
For more details on the features supported in each version, see the save
reference page.
2-56
Preferences
This table summarizes the core MATLAB confirmation dialog boxes. There
might be additional confirmation dialog boxes for other products you install.
2-57
2 Desktop
Confirm when When you load variables by dragging them from the Details Panel of
overwriting the Current Folder browser to the Workspace browser or Command
workspace variables Window.
via drag-and-drop
Prompt when editing When you type edit filename and filename does not exist in the
files that do not exist current folder or on the search path.
Prompt to exit debug When you try to save a modified file while in debug mode.
mode when saving file
For details, see “End Debugging”.
Prompt to save on When you have unsaved changes to a figure and program file and
activate you activate the GUI by clicking the Run button, for example.
For details, see “GUIDE Preferences”.
Prompt to save on When you have unsaved changes to a figure and program file and
export you select File > Export.
For details, see “GUIDE Preferences”.
Confirm changing When you have modified a callback signature in GUIDE.
default callback
For details, see “GUIDE Preferences”.
implementation
Confirm before exiting When you quit MATLAB.
MATLAB
Confirm when When you delete variables from the workspace using menu items.
deleting variables Does not appear with the clear function.
For details, see “Save, Load, and Delete Workspace Variables” on
page 5-9.
2-58
Preferences
For detailed information on setting up and using a source control system with
MATLAB, see “Set Up Source Control (Microsoft Windows)” and “Source
Control Interface on UNIX Platforms”.
2 Select a Java heap size value using the slider or spin box.
Note Increasing the Java heap size decreases the amount of memory
available for storing data in arrays.
3 Click OK.
4 Restart MATLAB.
If the amount of memory you specified is not available upon restart, MATLAB
resets the value to the default, and displays an error dialog box. To readjust
the value, repeat the previous steps.
2-59
2 Desktop
If increasing the heap size does not eliminate memory errors, check your Java
code for memory leaks. Eliminate references to objects that are no longer
useful. For more information, see the Java SE Troubleshooting guide at
http://www.oracle.com/technetwork/java/javase/index-138283.html.
Preference Usage
Active settings Select or import a set of predefined
keyboard shortcuts.
For details, see “Choose a Set
of Keyboard Shortcuts” on page
2-16 and “Use Keyboard Shortcuts
Settings Files Created on Other
Systems” on page 2-35.
Select any one of these options:
• Save As—Save active settings to
a file.
• Copy to clipboard— so you can
import into Microsoft Excel, for
example.
For details, see, “Display
Keyboard Shortcuts” on page 2-21.
• Compare active settings to
another set.
2-60
Preferences
Preference Usage
2-61
2 Desktop
Preference Usage
All possible conflicts Display conflicts when two or more
different actions have the same
shortcut.
For details, see “Evaluate and
Resolve Keyboard Shortcut
Conflicts” on page 2-29.
Remove the keyboard shortcut from
the selection in the All possible
conflicts list.
For details, see “Evaluate and
Resolve Keyboard Shortcut
Conflicts” on page 2-29.
Fonts Preferences
You can set and specify different fonts for desktop tools.
On the Home tab, in the Environment section, click Preferences > Fonts.
Then, set options as described in the table below.
Preference Usage
Desktop code font Specify the font (type, style, and size in points) for tools
assigned to use the desktop code font.
To change the list of tools that use the desktop code
font, see “Fonts Custom Preferences” on page 2-63.
Desktop text font Specify the font (type, style, and size in points) for tools
assigned to use the desktop text font.
To have the desktop text font use the same font as
your system, select Use system font. Otherwise, clear
Use system font and specify the type, style, and size
in points in the fields provided. To change the list of
2-62
Preferences
Preference Usage
tools that use the desktop text font, see “Fonts Custom
Preferences” on page 2-63.
Custom fonts See which tools currently do not use the desktop text
font or the desktop code font. By default, the Profiler
and Comparison Tool use a custom font.
Use antialiasing to smooth desktop Give the desktop a smoother appearance.
fonts
This option is not provided on Microsoft Windows or
Linux4 and UNIX5 platforms only.
Apple Macintosh platforms, because MATLAB follows
the operating system’s font settings on these platforms.
2-63
2 Desktop
Preference Usage
Desktop tools Select the desktop tool for which you want to view or customize
fonts, such as the Command Window or Editor.
Font to use Indicates the font currently being used in the selected desktop
tool. Use one of these fonts to change it.
• Desktop code
Uses the characteristics of the desktop code font, as
described in “Fonts Preferences” on page 2-62.
• Desktop text
Uses the characteristics of the desktop text font, as described
in “Fonts Preferences” on page 2-62.
• Custom
Uses the type, style, and size you specify in the fields.
For the Profiler and Comparison Tool, you can change the font
size, but changes to the font style (for example, bold or italic)
have no effect.
Colors Preferences
You can specify the text and background color for desktop tools, as well as
colors for highlighting syntax elements of MATLAB code.
On the Home tab, in the Environment section, click Preferences > Colors.
Then, set options as described in the table below.
2-64
Preferences
Preference Usage
Desktop tool colors Specify that desktop tools use the same text and
background colors that your platform uses for other
applications by selecting Use system colors.
Customize colors by clearing Use system colors, and
then choose Text and Background colors from the
drop-down menus.
These colors do not apply to the Help display pane, nor
to the Web browser.
For details, see “Changing Text, Background, and
Hyperlink Colors in Desktop Tools” on page 2-7.
MATLAB syntax highlighting Set colors to help you quickly identify elements of
colors MATLAB syntax in the Editor, Command Window,
Command History window, and the MATLAB shortcuts
callback area.
For details, see “Changing Syntax Highlighting Colors”
on page 2-8.
MATLAB Command Window Set colors to help you quickly identify errors, warnings,
colors and hyperlinks in the Command Window.
2-65
2 Desktop
Preference Usage
Code analyzer colors • Warnings—Specifies the color Code Analyzer uses to
identify code in the Editor for which there are warning
messages.
• Autofix highlight—Specifies the color Code Analyzer uses
to identify code in the Editor for which there is an automatic
fix.
Toolbars Preferences
You can customize some toolbars in the MATLAB application.
2-66
Preferences
Preference Usage
Toolbar Select the toolbar you want to customize.
Layout Rearrange the order of controls in the toolbar by dragging
and dropping them to a new location in the Layout.
Controls Select which buttons appear on the selected toolbar.
Web Preferences
Web preferences enable you to specify Internet connection information to
MATLAB.
Note
Limitations
• MATLAB supports nonauthenticated, basic, digest, and NTLM proxy
authentication types.
• You cannot specify proxy server settings using a script.
• There is no automated way to provide MATLAB with the proxy server
settings that your system browser uses.
You can set Web preferences, on the Home tab, in the Environment section.
Click Preferences > Web, and then adjust preference options as described in
the table below.
Preference Usage
Use a proxy server to Provide information that MATLAB needs to access the internet
connect to the Internet when your network uses a firewall or another method of
protection that restricts Internet access.
Proxy host Specify a value for the Proxy host. For example, 172.16.10.8
or ourproxy. If you do not know the values for your proxy
server, ask your system or network administrator for the
information.
2-67
2 Desktop
Preference Usage
Proxy port Specify an integer value for the Proxy port. For example, 22.
If you do not know the values for your proxy server, ask your
system or network administrator for the information.
Use a proxy with Specifies that your proxy server requires a user name and
authentication password.
Proxy username Specify the proxy server user name.
Proxy password Specify the proxy server password.
6. UNIX is a registered trademark of The Open Group in the United States and other
countries.
2-68
3
Entering Commands
a = 1
a =
When you do not specify an output variable, MATLAB uses the variable ans,
short for answer, to store the results of your calculation.
sin(a)
ans =
0.8415
The value of ans changes with every command that returns an output value
that is not assigned to a variable.
b = 2;
You also can enter more than one statement on the same line by separating
statements. To distinguish between commands, end each one with a comma
or semicolon. Commands that end with a comma display their results, while
3-2
Enter Statements in Command Window
commands that end with a semicolon do not. For example, enter the following
three statements at the command line:
A =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
C =
3.6170 5.1064 0.2128 1.7021 3.1915
4.8936 1.0638 1.4894 2.9787 3.4043
0.8511 1.2766 2.7660 4.2553 4.6809
2.1277 2.5532 4.0426 4.4681 0.6383
2.3404 3.8298 5.3191 0.4255 1.9149
To recall previous lines in the Command Window, press the up- and
down-arrow keys, ↑ and ↓. Press the arrow keys either at an empty command
line or after you type the first few characters of a command. For example, to
recall the command b = 2, type b, and then press the up-arrow key.
You can evaluate any statement already in the Command Window. Select the
statement, right-click, and then select Evaluate Selection.
In the Command Window, you also can execute only a portion of the code
currently at the command prompt. To evaluate a portion of the entered code,
select the code, and then press Enter.
hello
3-3
3 Entering Commands
Be aware that:
• You cannot use the Function Browser for blocks. Instead use the doc
function or the Help browser.
• You cannot use the Function Browser to find functions you created or that
other users provided. Instead, use “Finding Files and Folders” on page 6-24.
The Function Browser closes when you move the pointer outside of it. To keep
the Function Browser open, drag it by the top edge to a different location.
The following illustration shows how you browse for functions by expanding
categories of interest.
3-4
Find Functions Using the Function Browser
The following illustration shows results when you search, for example, for
filter.
3-5
3 Entering Commands
The pop-up window automatically closes when you move your pointer to a
new item in the results list. To keep the pop-up window open, drag it by
the top edge to a different location.
• Add a function name after the cursor in the Command Window or Editor by
double-clicking the name in the Function Browser results list.
3-6
Find Functions Using the Function Browser
• Drag the function name from the Function Browser into any tool or
application.
• Right-click the function name in the Function Browser to display other
options.
When more than one function in MATLAB has the same name, the folder for
the overloaded function appears in parentheses.
For example:
• filter is in MATLAB
• filter (signal) is in the Image Processing Toolbox™
• filter (timeseries) is in the timeseries folder in MATLAB
When a result does not include any blue highlighting, the matching term is
not part of the name, syntax, or brief description. The term is somewhere else
in the reference page.
• You can show or hide the Browse for functions button in the Command
Window. On the Home tab, in the Environment section, select
3-7
3 Entering Commands
Product
area
3-8
Format Output in Command Window
x =
1.3333 0.0000
3-9
3 Entering Commands
format loose
format compact
Note The text display format affects only how numbers are shown, not how
MATLAB computes or saves them.
3 Click OK.
Suppress Output
To suppress code output, add a semicolon (;) to the end of a command. This is
particularly useful when code generates large matrices.
3-10
Format Output in Command Window
Running the following code creates A, but does not show the resulting matrix
in the Command Window:
A = magic(100);
• On the Home tab, in the Code section, select Clear Commands > Clear
Command Window to clear the Command Window scroll buffer.
• Use the clc function to clear the Command Window scroll buffer.
• Use the home function to clear your current view of the Command Window,
without clearing the scroll buffer.
3-11
3 Entering Commands
Stop Execution
To stop execution, press Ctrl+C or Ctrl+Break
On Apple Macintosh platforms, you also can use Command+. (the Command
key and the period key).
Ctrl+C does not always stop execution for files that run a long time, or
that call built-ins or MEX-files that run a long time. If you experience this
problem, include a drawnow, pause, or getframe function in your file, for
example, within a large loop.
Also, Ctrl+C might be less responsive if you start MATLAB with the
-nodesktop option.
Note For certain operations, stopping the program might generate errors in
the Command Window.
3-12
Find Text in Command Window or History
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, MATLAB
continues searching after beeping.
To search for the specified text in other MATLAB desktop tools, change the
selection in the Look in field.
Clearing the command window (for example, with the clc function), empties
the scroll buffer. The cleared text is no longer available for searching. To
3-13
3 Entering Commands
clear your display in the Command Window without clearing the buffer, use
the home function.
With the incremental search feature, you do not have to leave the Command
Window while you perform your search.
When you enter lowercase letters in the Inc Search field, incremental
search looks for both lowercase and uppercase instances of the letters. For
example, if you enter b, incremental search looks for b and B. However, if
you enter uppercase letters, incremental search only looks for instances
that match the case you entered.
3-14
Find Text in Command Window or History
If you search for a string that does not appear in the Command Window
text, Failing appears in the incremental search field.
The Inc Search field disappears. The cursor remains at the position where
the text was last found, with the search text highlighted.
1 Type the first few letters or numbers of the entry you want to find in the
Command History window.
The Command History window searches backwards and selects the previous
entry that begins with the letters you typed. A tooltip with the text: Search
history for:, appears at the top of the Command History window.
3-15
3 Entering Commands
• Find the previous or next occurrence of the entry with the up and down
arrow keys, respectively.
• Highlight each occurrence of the entry found, while you search for
additional instances, press the Ctrl key with the up or down arrow key.
• Highlight all instances of the entry, press Ctrl+A.
On the Command History title bar, click , and then select Find. The search
begins at the current cursor position. Find does not identify entries in
collapsed nodes.
3-16
Create Shortcuts to Rerun Commands
1 On the Home tab, click New, and then select Command Shortcut.
If the Shortcuts tab is currently on the desktop, you can also click New
Shortcut in the Manage section.
b In the Callback field, type statements you want the shortcut to run.
You also can drag and drop statements from the Command Window,
Command History Window, or a file.
format compact
clear
workspace
filebrowser
clc
c In the Category field, type the name of a new category or select an existing
category from the drop-down list. If you leave this field blank, the shortcut
appears in the General section of the toolbar.
3-17
3 Entering Commands
e Click Save.
The shortcut icon and label appear on the toolbar. If you have more shortcuts
on the toolbar than the desktop can display concurrently, use the drop-down
list to access them all.
To organize and edit shortcuts, on the Shortcuts tab, in the Manage section,
click Organize Shortcuts to open the Shortcuts Organizer dialog box.
All the statements in the shortcut Callback field execute as if you ran those
statements from the Command Window, although they do not appear in the
Command History window.
3-18
Set Command Window Preferences
Preference Usage
Text display Select a Numeric format option to specify the output format of
numeric values in the Command Window.
For details, see “Format Floating-Point Numbers” on page 3-10.
Select a Numeric display option to specify whether blank lines
appear in Command Window output. To suppress blank lines,
select compact. To display blank lines, select loose.
Display Select Wrap lines to make each line of input or output in the
Command Window break into multiple lines to fit within the
current width of the Command Window.
For details, see “Wrap Lines of Code to Fit Window Width” on
page 3-10.
Select Set matrix display width to eighty columns to limit the
width of matrix output.
Note If you also select Wrap lines, and the width of the Command
Window is less than 80 characters, each row of 80 characters of
matrix output wraps to fit within the width of the Command
Window.
3-19
3 Entering Commands
Preference Usage
Note This setting does not apply if you have enabled tab
completion. To change tab completion settings, on the Home tab,
select Preferences > Keyboard.
3-20
Set Keyboard Preferences
Preference Usage
Tab completion Select the tool or tools in which you want the Tab key to complete
names known to MATLAB after you type the first few letters of
the name.
For details, see “Tab Completion” on page 3-25.
3-21
3 Entering Commands
Preference Usage
Delimiter Matching Specify when and if MATLAB alerts you to matched and
mismatched delimiters. Delimiters include parentheses,
brackets, braces, and, in the Editor only, paired keywords.
If you select Match while typing, MATLAB alerts you to
matched and mismatched delimiters as you type.
If you select Match on arrow key, MATLAB alerts you to
matched and mismatched delimiters when you move the cursor
over a delimiter using an arrow key.
For details, see “Delimiter Matching” on page 3-24.
Select one of these Show match with options to specify how
MATLAB indicates matching delimiters:
3-22
Check Syntax As You Type
Syntax Highlighting
To help you identify MATLAB elements, some entries appear in different
colors in the Command Window. This is known as syntax highlighting. By
default:
if A > B
'greater'
elseif A < B
'less'
end
Except for errors, output in the Command Window does not appear with
syntax highlighting.
When you paste or drag a selection from the Editor to another application,
such as Microsoft Word, the pasted text maintains the syntax highlighting
colors and font characteristics from the Editor. MATLAB software pastes the
selection to the Clipboard in RTF format, which many Microsoft Windows
and Macintosh applications support.
3-23
3 Entering Commands
Delimiter Matching
MATLAB indicates matched and mismatched delimiters, such as parentheses,
brackets, and braces, to help you avoid syntax errors. MATLAB also indicates
paired language keywords, such as for, if, while, else, and end statements.
You can change delimiter matching indicators, and when and if they
appear. On the Home tab, in the Environment section, select
Preferences > Keyboard.
3-24
Check Syntax As You Type
Tab Completion
MATLAB can help you avoid typographical errors by completing the names
of functions, models, MATLAB objects, files, folders, variables, structures,
and Handle Graphics property names.
To complete names in the Command Window, type the first few characters of
the name you want to complete, and then press the Tab key.
If MATLAB presents a list of possible matches, use the arrow keys to select
the name you want, and then press the Tab key.
• Clear the list without selecting anything, by pressing the Esc (escape) key.
• Narrow a long list before making a selection, by adding additional
characters to your original term.
• Complete parts of a name that uses dot notation by adding a dot, and then
pressing the Tab key.
• Complete the names and values of Handle Graphics properties. Begin
typing the first part of a property, and then press the Tab key. Type a
comma after each property.
For MATLAB to complete a file or folder name, it must be on the search path
or in the current folder. Variables and properties must be in the current
workspace.
• Nested functions only when they are available at the current location of
the cursor.
3-25
3 Entering Commands
• Field names of structure arrays defined only within the active file.
• Method or property names for objects defined only within the active file.
Note To add spaces within statements using the Tab key in the Editor, first
add a space, and then press Tab. Otherwise, when tab completion is enabled,
MATLAB attempts to complete a name.
1 In the Command Window, type help cont, and then press Tab.
3-26
Check Syntax As You Type
3 At the command prompt, add a dot after containers, and then press Tab.
help containers.Map
4 At the command prompt, add a dot after Map, and then press Tab.
5 Scroll down the list, select keys, and then press the Tab key.
Function hints appear for both MATLAB installed functions and functions
you create. The syntax hints for MATLAB functions comes from the
documentation. The syntax for functions you create comes from the function
definition statement (first executable line) in the MATLAB program file. That
file must be on the search path or in the current folder.
3-27
3 Entering Commands
You can type a variable for any argument that appears in blue. Enter your
variable names, and not the argument names shown in the window.
The displayed syntax options change, based on the argument you just entered.
Some function names are overloaded. That is, there are methods with the
same name as a function that support different types of inputs. Overloaded
methods require that you pass an object as the first input. When you specify
the object name, the syntax hints update to reflect the associated method,
as shown.
Function syntax hints are suggestions only. Some allowable arguments might
not appear, or could be in black text when they should be blue.
Function hints are enabled by default. To change this setting, on the Home
tab, in the Environment section, select Preferences > Keyboard, and then
set the options for Function hints.
3-28
Command History
Command History
In this section...
“What Is the Command History?” on page 3-29
“Using Command History Commands” on page 3-29
“Changing the Command History Date Format” on page 3-31
“Command History Preferences” on page 3-31
MATLAB saves statements that run in the Command Window to the to the
history file, history.m. This includes statements you run using the Evaluate
Selection item on context menus in tools such as the Editor, Command
History, and Help browser. By default, MATLAB automatically saves the
command history file after each command. The history file does not include
every action taken in MATLAB. For example, modifications of values in the
Variable Editor are not included in the Command History.
3-29
3 Entering Commands
Note You cannot recall entries you delete from the Command
History window.
Select the entries to delete, and then right-click and select Delete
Selection from the context menu, or press the Delete key.
3-30
Command History
1 Change the short date format for your operating system as described in its
documentation.
Note Clearing the command history deletes all entries from the Command
History window. You can no longer recall those entries in the Command
Window.
Note When you exclude statements from the command history file, you
cannot recall them in the Command Window, nor can you view them in the
Command History window.
3-31
3 Entering Commands
Preference Usage
Settings Save exit/quit commands saves exit and quit commands in the
command history.
Save consecutive duplicate commands saves consecutive
executions of the same statement in the command history.
• With this option selected, if you run magic(5) two times in a row,
both entries for magic(5) remain in the command history.
• With this option cleared, the command history retains only one
entry for magic(5). If you then run magic(10), the command
history retains both entries.
Saving Save history file on quit saves the command history file only
when you end a MATLAB session. If the session ends abnormally,
such as due to a power failure, then MATLAB does not save the
history file for that session.
Save after n commands saves the command history file after
MATLAB adds n statements to it. This option reduces the loss of
entries to the saved history in case of an abnormal termination of
the MATLAB session.
Don’t save history file is useful when multiple users share the
same machine. It prevents each user from viewing the statements
others have run.
Any entries already in the command history remain unless you first
delete entries from the Command History window.
3-32
4
4-2
Run Examples
Run Examples
In this section...
“Code Excerpts” on page 4-3
“Example Scripts” on page 4-3
Code Excerpts
Run code from any page in the documentation by selecting the code,
right-clicking, and then selecting Evaluate Selection.
Example Scripts
Featured example scripts include a button at the top of the Help browser
for opening the script in the Editor.
4-3
4 Help and Product Information
• Run one section of the script at a time and view the incremental results.
Select the first section, and then step through the script by clicking Run
and Advance, .
4-4
Search Syntax and Tips
The search engine ignores common, insignificant words such as a, an, the,
and of, unless they are part of an exact phrase in quotation marks. It also
ignores capitalization, punctuation, and special characters such as +. To find
a symbol or special character:
• Search for the word instead of the symbol or character, such as plus
instead of +.
• View the documentation on Operators and the Symbol Reference.
• Search the PDF documentation, available from the documentation home
page.
4-5
4 Help and Product Information
The Help browser search evaluates NOT operators first, OR operators second,
and AND operators last. For example,
finds pages that contain either plotting tool or plot tools and contain
workspace, but do not contain time series.
4-6
Bookmark and Share Page Locations
When you add a favorite, do not change the Callback. MATLAB requires
special values to create a shortcut that opens the page in the Help browser. In
addition, if you want the bookmark to appear in your list of favorites, keep the
Category set to Help Browser Favorites, as shown.
Note You cannot migrate favorites that you save in one MATLAB release
to a new release.
4-7
4 Help and Product Information
The Help Page Location dialog box provides two ways to access the page:
• A web command to run from the command line that opens the page from
the installed documentation. This command is subject to change between
releases, so it is not always accurate for someone running a different
version of MATLAB.
• A URL for the page corresponding to your product version at the
MathWorks Web site. This documentation is available to anyone, even
if they do not have MathWorks products. However, to access archived
documentation from previous releases, you must log in with a MathWorks
Account.
Note If you are running a prerelease version, the URL is invalid because
the documentation does not yet exist on the Web site.
4-8
Contact Technical Support
2 When requested, log in using your MathWorks Account email address and
password. If you do not have a MathWorks Account, create one.
4-9
4 Help and Product Information
4-10
Demos Are Now Called Examples
4-11
4 Help and Product Information
For more information about changes to the Help browser, see the R2012b
MATLAB Release Notes.
4-12
Help Preferences
Help Preferences
To set Help preferences:
1 On the Home tab, in the Environment section, click Preferences > Help.
Preference Usage
Documentation Location Specify whether to view the documentation provided with
your installed products or the documentation on the Web
at http://www.mathworks.com/help. Viewing the Web
documentation requires an Internet connection and a
MathWorks Account.
If your preference is set to view Web documentation, but your
Internet connection becomes unavailable, MATLAB changes
the preference to view the installed documentation. You can
reset the preference after your connection is restored.
Changes to this preference apply only to new Help browser
Selected Products Select the products to include for viewing and searching
tabs.
documentation in the Help browser or Function browser.
If your Documentation Location is set to view documentation
on the Web, then you can select Show products that are
not installed to select and access documentation for all
MathWorks products, even if you do not have those products
installed.
When the Help browser is already open, changes to this
preference apply only to new Help browser tabs.
4-13
4 Help and Product Information
Preference Usage
Quick Help Display Specify whether help links display content in the Help browser
or in a small window. This preference applies to content that
you access using:
4-14
Japanese Documentation
Japanese Documentation
Many MathWorks products provide versions of the documentation translated
from English to Japanese. However, the translated documentation usually is
not available until about 2 months after the initial release of a new product
version.
The new version of most products installs the translated documentation from
the previous version and the English documentation for the current version.
To view the English documentation, set the Help Language preference to
English. To set Help preferences, access the Environment section on the
Home tab, and click Preferences > Help.
4-15
4 Help and Product Information
4-16
5
A = magic(4);
R = randn(3,4,5);
The Workspace browser displays the variables in your workspace. From the
Workspace browser, you can select variables to view, modify, or plot.
By default, the Workspace browser displays the base workspace. You also can
view function workspaces if MATLAB is in debug mode. For more information,
see “Debugging Process and Features” and the dbstack and evalin functions.
You can display additional columns, such as size (dimensions) and size in
bytes in the Workspace browser. On the Workspace browser title bar, click ,
and then click Choose Columns.
5-2
View, Edit, and Copy Variables
Action Procedure
List current workspace Use the who function.
variables
To also list information about size and
class, use the whos function.
Display variable contents in Type the variable name at the Command
the Command Window prompt.
Open a variable in the Do one of the following:
Variables editor
• Use the openvar function. For example,
to open the variable A, type
openvar('A')
5-3
5 Workspace Browser and Variable Editor
Action Procedure
After opening a variable, you can view and edit its values graphically.
This example shows how to open a variable, and then navigate and edit
its contents graphically. Note that you cannot edit elements or subsets of
multidimensional arrays in the Variables editor.
A = magic(4);
C = {A A A};
openvar('C')
Lock icons, which can appear during debugging, denote protected and
private properties of an object, indicating you do not have get access to
those values outside class methods.
5-4
View, Edit, and Copy Variables
3 Double-click element C{1,1} to view the contents of that cell. The element
opens in a new document within the Variables editor.
4 Edit the value of an array element by clicking the element, and then typing
a new value. Press Enter, or click another element.
5-5
5 Workspace Browser and Variable Editor
Increase the size of the array in C{1,1} by entering a value in element (5,5).
Empty elements in numeric arrays fill with zeros. In a cell array, empty
elements fill with empty arrays.
5 Remove a row by clicking in its row header. Right-click, and then select
Delete Row.
7 Paste the cut elements into another column by selecting the element where
you want the insertion to begin. Right-click, and then select Paste.
8 Change how numbers display when editing variables. On the View tab, in
the Format section, select a number display format.
9 On the View tab, use the Go Up button to return to the cell array or
structure.
Changes you make in the Variables editor are automatically saved in the
workspace.
Changes you make to variables via the Command Window or other operations
automatically update the information for those variables in the Variables
editor.
5-6
View, Edit, and Copy Variables
Action Procedure
Create a new variable from For a variable open in the Variables editor,
an existing variable. select an element, data range, row, or column
in an array, and then select New from
Selection.
Rename a variable In the Workspace browser, do either of the
following:
Tip If you cut and paste values from the Variables editor into text files or
other applications, you can change the character that delimits decimals in the
data that is exported. You might do this, for instance, if you provide data to a
locale that uses a character other than the period (.). To change the delimiter
character, specify a Decimal separator for exporting numeric data via
system clipboard in the “Variables Preferences” on page 5-15.
5-7
5 Workspace Browser and Variable Editor
5-8
Save, Load, and Delete Workspace Variables
The following table describes how to save, view, and load workspaces.
save('june10')
save('june10','A','R')
load('june10')
5-9
5 Workspace Browser and Variable Editor
5-10
Save, Load, and Delete Workspace Variables
clear A R
5-11
5 Workspace Browser and Variable Editor
If you show statistical columns in the Workspace browser, and you work with
very large arrays, you might experience performance issues when the data
changes as MATLAB updates the statistical results. To improve performance,
consider one or both of the following:
5-12
Statistical Calculations in the Workspace Browser
5-13
5 Workspace Browser and Variable Editor
Preference Usage
n element and smaller arrays Limit the size of arrays for which
show statistics the Workspace browser displays
statistics to improve performance
when MATLAB updates the
statistical results in the Workspace
browser.
For more information, see
“Statistical Calculations in the
Workspace Browser” on page 5-12.
Handling NaN values in Specify whether NaN values
calculations be included or excluded from
calculations for the statistics
• Use NaNs when calculating displayed in the Workspace browser.
statistics
• Ignore NaNs when calculating
statistics
5-14
Set Workspace and Variable Preferences
Variables Preferences
When working in the Variables editor, Variables preferences enable you to
specify the array formatting, cursor movement, and the decimal separator for
exporting data using the system clipboard.
Preference Usage
Format Select an option from the Default array format
to specify the default array output format of
numeric values displayed in the Variables editor.
This format preference affects only how numbers
display, not how MATLAB computes or saves
them. For information on formatting options, see
the reference page for the format function.
Editing Specify where the cursor moves to after you type
an element, and then press Enter:
5-15
5 Workspace Browser and Variable Editor
5-16
6
You can always load files and execute scripts and functions that are in the
current folder, even if that folder is not currently on the MATLAB search
path. Functions in the current folder take precedence over functions with the
same file name that reside anywhere on the search path.
Viewing and Changing the Current Folder. You can view and change
the current folder using various desktop tools and functions, as described in
the following table. To specify the current folder programmatically when
MATLAB starts, see “Startup Folder for the MATLAB Program” on page 1-12.
6-2
Understanding File Locations in MATLAB®
To: Do this:
Identify the current Use one of the following:
folder
• The current folder toolbar — if the full path
is not visible, click .
matlabroot
matlabroot is the folder where you installed MATLAB. The location differs
for each installation of MATLAB. Determine its location by running the
matlabroot function. When you start MATLAB, your current folder can be
matlabroot, but in practice it is usually a different folder.
6-3
6 Managing Files in MATLAB®
To see a list of all toolbox folder names supplied with MathWorks products,
run:
dir(fullfile(matlabroot, '/toolbox'))
The location of the userpath MATLAB folder varies by platform and system
configuration. To determine the location, run the userpath function.
6-4
Understanding File Locations in MATLAB®
If you create subfolders within the MATLAB folder, make the new subfolders
accessible to MATLAB.
• Make the files accessible to MATLAB by adding their folders to the search
path.
• Do not store the files in the folders provided for MathWorks products.
6-5
6 Managing Files in MATLAB®
Type filesep in the Command Window to determine the correct file separator
character to use when working with files programmatically.
Some MATLAB functions also support relative path names. The reference
page for a function specifies the valid types of path name. Unless otherwise
noted, the path name is relative to the current folder. For example:
• /myfolder refers to the myfolder folder in the current folder and myfile.m
refers to the myfile.m file in the current folder.
• ../myfolder/myfile.m refers to the myfile.m file in the myfolder folder,
where myfolder is at same level as the current folder. Each repetition of
../ at the beginning moves up an additional folder level.
Tip If multiple documents are open and docked in the Editor, you can copy
the absolute path of any of these documents to the clipboard. This is useful if
you need to specify the absolute path in another MATLAB tool or an external
application. Right-click the document tab, and then select Copy Full Path
to Clipboard
6-6
Understanding File Locations in MATLAB®
Furthermore, if multiple files with the same name, but different extensions
exist in the same folder, then MATLAB searches among the files in the folder
in this precedence order:
• MEX-files
• MDL (Simulink model) files
• P-code files
• MATLAB code files (those with a .m extension)
For example, suppose myfile.m is on the search path, but MYFILE.M is not.
If you type MYFILE at the MATLAB command prompt, then MATLAB runs
myfile.m, but warns you that there is a case mismatch and advises you that
this warning will become an error in a future release.
If myfile (a MEX-file) and MYFILE.m are on the search path, and you type
MYFILE at the command prompt, MATLAB runs MYFILE.M, even if myfile is
higher on the search path.
To see which file MATLAB will use without running that file, use which with
the all option. For example, which myfile.m all.
Case Sensitivity of File Names When You Load a MAT-File. When you
call load and specify a file without an extension, MATLAB searches for a
MAT-file. Case-sensitivity depends on the operating system where MATLAB
is running, as follows:
• Linux
If you attempt to load MYFILE, and MYFILE.MAT is anywhere on the
MATLAB search path, then MATLAB loads MYFILE.MAT. This is true, even
6-7
6 Managing Files in MATLAB®
Case Sensitivity of File Names When You Save a MAT-File. When you
call save and specify a MAT-file without an extension, MATLAB saves the
file to the current folder. Case-sensitivity depends on the operating system
where MATLAB is running, as follows:
• Linux
MATLAB saves the file using the case you specify. Two files with the same
name, but different cases can exist in the same folder.
• Windows
Because the Windows operating system considers two files with the same
name to be the same file (regardless of case), you cannot have two files with
the same name in the same folder. If you save MYFILE, and myfile.mat
already exists in the current folder, then MYFILE.MAT replaces myfile.mat
without warning. If you save myfile, and MYFILE.mat already exists in
the current folder, the contents of myfile.mat replace the contents of
MYFILE.mat, but the name remains MYFILE.mat.
6-8
Understanding File Locations in MATLAB®
• For a relative path name, you might need to use fewer than 260 characters.
When the Windows operating system processes a relative path name, it can
produce a longer absolute path name, possibly exceeding the maximum
length.
If you get unexpected results when working with long path names, use
absolute instead of relative path names. Alternatively, use shorter names
for folders and files.
delete('temp file.m') % Function syntax works for a file name containing a space
delete temp file.m % Command syntax does NOT work for a file name containing a space
Some functions accept partial path names. The reference page for a function
typically specifies the valid types of path names.
• Specify a location more conveniently than by using the full path name.
6-9
6 Managing Files in MATLAB®
help database/set
• Locate method files. For example, to get help for the time series object
plot method type:
help timeseries/plot
Be sure to specify enough of the path name to make the partial path name
unique.
See Also
6-10
Working with Files and Folders
You can view information about folders from the MATLAB Desktop like you
can from operating system windows. The principal Desktop tool for working
with files and folders is the Current Folder browser. Like other Desktop
components, you can dock the Current Folder browser or open it as a separate
window. The Current Folder browser displays details about files in your
current folder and within the hierarchy of the folders it contains. You can
modify the kinds of information it displays to suit your needs, for example by
reordering or deleting specific columns of information.
The following sections explain what you can do with the Current Folder
browser and how to use it.
6-11
6 Managing Files in MATLAB®
The Current Folder browser shows the contents of the current folder.
Double-clicking a subfolder displays its contents, and makes that folder the
current folder.
When you click the search button , the address bar becomes a search field.
6-12
Working with Files and Folders
Tip For information on changing the date format in the Current Folder
browser, see “Customizing the Column Display” on page 6-17
6-13
6 Managing Files in MATLAB®
By default, the Auto-refresh view from file system option is on, with
an update time of 3 seconds. Every 3 seconds, the Current Folder browser
checks for and reflects changes made from programs and tools other than
MATLAB.
3 Click OK.
6-14
Working with Files and Folders
6-15
6 Managing Files in MATLAB®
2 Select the Indicate inaccessible files check box to enable this feature;
deselect it and skip to step 5 to disable this feature.
3 Move the Text and icon transparency slider to adjust the level of
dimming.
View the region below the slider to preview how your choice will affect the
appearance of files in the Current Folder browser.
5 Click OK.
For more information, see “Private Functions” and “What Is the Search
Path?” on page 6-71.
The Current Folder browser lists details about files and folders in columns,
beneath file and folder names, and in the details panel. Any file that is
modified in the Editor, but not yet saved has an asterisk (*) next to it in
the Current Folder browser. The browser displays columns for Size, Date
Modified, Type, and Description. You can modify the information it
displays. You also use this tool to perform operations on files and folders, such
as moving, compressing, renaming, creating, and deleting them.
6-16
Working with Files and Folders
In addition, consider:
• Hiding the Type column if the icon column provides enough information
about the type.
• Sorting or grouping by a column without showing the column.
In the Current Folder browser, click , and then select Sort By or Group
By. Then, choose the method by which you want to sort or group columns.
To Modify Columns.
To Change the Date Format. MATLAB uses your operating system’s short
date format to display dates in the Current Folder browser and the Command
History window. To change the date format, for instance from MM/DD/YYYY
to DD/MM/YYYY, (where MM is the numerical value for the month, DD is the
numerical value for the day, and YYYY is the numerical value for the year):
1 Change the short date format for your operating system. For instructions,
see your operating system documentation.
6-17
6 Managing Files in MATLAB®
Descriptions appear in gray text beneath the name of the file or folder. When
the Current Folder browser window is wide enough, descriptions display on
the same line as file names. The Current Folder browser shows descriptions
only for files and folders that are relevant to products from MathWorks. How
the Current Folder browser gets the description depends on the type of item:
• MATLAB program files — The description is the first line of the help
comments, known as the H1 line.
• Simulink Models — The description is from the Description pane of the
Model Properties dialog box. Use the Current Folder browser to view model
descriptions without starting the Simulink software.
• Folders — The description is the first comment line of the Contents.m
file for the folder.
To provide descriptions for your own files and folders, see “Add Help for
Your Program”.
6-18
Working with Files and Folders
Detail Up arrow
panel
File and Folder Details. When you select a file or folder, the details panel
displays more information about that file or folder, if possible. For example, if
you select a MATLAB code file, the details panel shows the main functions or
local functions that the file contains.
Image File Details. When you select a JPEG, JPG, BMP, WBMP, PNG, or GIF
image, the details panel displays a thumbnail of the image and lists its width
and height in pixels. To open the Import Wizard, double-click the thumbnail.
6-19
6 Managing Files in MATLAB®
Viewing Unsaved File Changes. When you select a file that is currently
open in the Editor and that contains unsaved changes, an asterisk (*) appears
after that file name. The Current Folder browser columns reflect the content
of the unsaved file. For instance, if you open a file, change it from a script to a
function, and modify the H1 line, then the icon, type name, and description
update in the Current Folder browser.
The preview in the details panel also reflects the unsaved file content, not the
content on disk. For instance, in the following example, PropertyTwo exists
in the modified MyClass.m file, but not the MyClass.m file on disk.
6-20
Working with Files and Folders
• Local functions
• Cells
• Properties
• Methods
To open the file in the Editor, scroll to the start of the element in the details
panel and double-click the element.
Viewing and Loading MAT-File Variables. Use the details panel to view
the name, class, and value of all variables in the selected MAT-file. To load a
variable into the workspace, select it in the details panel and drag it to the
Workspace browser. The folder containing the MAT-file does not need to be
on the search path for you to load it in this way.
6-21
6 Managing Files in MATLAB®
You can sort and then group, or group and then sort.
Regardless of the sorting and grouping options selected, the Current Folder
browser lists folders and files separately.
Tip To view only files of a certain type (for example, files having a .m
extension) use a simple search. See “Simple Search for File and Folder Names
in the Current Folder Browser” on page 6-24.
1 In the Current Folder browser, click , and then select Sort By.
Alternatively, click the column header by which you want to sort. Click it
again to reverse the direction of sorting.
1 In the Current Folder browser, click , and then select Group By.
Each group has a label. To hide the items in a group, click the collapse button
(–) next to the label.
6-22
Working with Files and Folders
To turn off grouping, click in the Current Folder browser, and then select
Group By > Stop Grouping.
6-23
6 Managing Files in MATLAB®
1 Position the pointer in the list of files and folders in the current folder.
As you type, the Current Folder browser searches downward from the top of
the window, looking through all expanded folders. It selects the first entry
in the current folder whose name begins with the characters you typed.
Typeahead and find as you type are other names for this feature.
1 In the current folder toolbar, change the current folder to be the one you
want to search.
6-24
Finding Files and Folders
3 Type the absolute path name or begin typing a file name. The asterisk
character (*) is a wildcard.
4 Press Enter:
• If you typed a path name, that path becomes the current folder.
• If you typed a file name, MATLAB displays all files within the current
folder (including its subfolders) that match that file name.
For example, to shows only file names that begin with coll and have a .m
extension, type coll*.m
6 Clear the results and show all items in the current folder by pressing the
Esc key.
Instant search and filtering are other names for this feature.
6-25
6 Managing Files in MATLAB®
2 Search for file names containing a specified string by typing the string in
the Find files named field.
3 Search for a specified string in the content of files by typing the string in the
Find files containing text field.
For example, search for plot. Alternatively, select text in the Command
Window or Editor and that text appears in the field.
• For partial word searching in file contents, select Contains text under
the More options Search type.
• Find an exact full-string match by selecting Matches whole word.
4 Specify file types to search for by selecting one of the options listed in the table.
One file type For Include only file type(s), select the file type you are
looking for.
For example, select *.m to limit the search to MATLAB
program files.
All file types
a For Include only file type(s), select All files (*).
6-26
Finding Files and Folders
6 Further restrict the search using More options. For example, use the Skip
files over option. It ignores large files that could take a long time to look
through.
The Find Files tool presents the search results in the right pane of the dialog
box, with a summary at the bottom. For text searches, results include the
line number and line of code.
• Click to the left of an icon and drag up or down to select contiguous items
• Shift+click to select contiguous items
• Ctrl+click to select non-contiguous items
2 Right-click and select one of the Open options from the context menu.
For details about the Open options, see “Opening and Running Files” on
page 6-40.
6-27
6 Managing Files in MATLAB®
b Click Edit.
3 In the resulting Edit Skipped File Extension dialog box, specify which file
types to look in and which to ignore:
4 Add any file types not listed that you want to skip or look for:
a Enter the file extension in the field at the top of the dialog box.
b Click Add.
The example at the end of this procedure shows the scc file type added.
5 Reduce the size of the list by removing any file extensions irrelevant to your
search:
a Select the name of the extension.
b Click Remove.
6-28
Finding Files and Folders
When you use the Find Files tool, search ignores the selected file types after
making the changes.
• In the Current Folder browser, right-click the file or folder, and then select
Show in Explorer or Show in Finder.
• In the Current Folder browser, right-click in white space, and then select
Open Current Folder in Explorer or Open Current Folder in Finder.
6-29
6 Managing Files in MATLAB®
The Windows Explorer or Mac Finder opens to the folder containing the
selected item.
6-30
Creating, Opening, Changing, and Deleting Files and Folders
• “Creating Files and Folders with the Current Folder Browser” on page 6-31
• “Creating and Updating MAT-Files with the Current Folder Browser” on
page 6-32
• “Creating and Managing Zip File Archives” on page 6-33
• “Creating Files and Folders Using Functions” on page 6-36
1 In the Current Folder browser, navigate to the folder where you want to
create a file or folder.
For guidance on where to create files, see “Locations for Storing Your Files”
on page 6-4.
2 Right-click in white space, and then select one of the following from the
context menu:
• New Folder.
MATLAB creates and selects a folder named New Folder.
• New File > file-type,
6-31
6 Managing Files in MATLAB®
MATLAB creates and selects a new file named untitled with the
appropriate extension.
File names must start with a letter, and can contain letters, digits, or
underscores.
4 Press Enter.
1 In the Current Folder browser, change the current folder to the folder where
you want to save the variables. See “Locations for Storing Your Files” on
page 6-4.
2 In the Workspace browser, select a variable to save. Hold down the Ctrl key
and click any other variable names you want to include in the MAT-file.
3 Drag the selected variables from the Workspace browser to the Current
Folder browser.
• Create a MAT-file by dropping the variables onto any empty location in the
Current Folder browser. Then name the file.
• Update an existing MAT-file by dropping the variables onto the file name.
MATLAB warns you when the MAT-file contains variables of the same
name. To update the existing variables, click Continue. Otherwise, click
Cancel.
6-32
Creating, Opening, Changing, and Deleting Files and Folders
You can suppress the warning. On the Home tab, in the Environment
section, click Preferences > General > Confirmation Dialogs. Then,
clear the preference, Confirm when overwriting variables in
MAT-files.
See also “Opening Files and Importing Data Using the Current Folder
Browser” on page 6-40.
Viewing the Contents of Zip Files. To view the contents of a zip file
without extracting any files it contains, click the associated + (expand) button
in the Current Folder browser. This feature is helpful when you want to:
By default, files within a zip file appear dimmed to indicate that they are not
on the MATLAB path.
Creating Zip Archives. You can either create an empty archive, or select
files, folders, or both to create an initial archive. In either case, you can add
more files later.
6-33
6 Managing Files in MATLAB®
Right-click white space, and then select New File > Zip File.
• Create a populated zip file from selected files, folders, or both:
Select the folders and files you want to archive, right-click, and then
select Create Zip File.
2 Type over the default file name to specify a descriptive name, for example
listmaster_export.zip, as shown here.
Extracting Files from Zip Files. To extract a single file from within a zip
file in the Current Folder browser, do one of the following:
• Copy a file name and paste it into a folder in the Current Folder browser.
• Drag the file into a folder in the Current Folder browser.
MATLAB extracts the file and saves it to the folder where you dragged or
pasted it.
To extract all the files from a zip file, do one of the following:
6-34
Creating, Opening, Changing, and Deleting Files and Folders
MATLAB extracts the entire contents of the zip file into a folder having the
same name as the zip file.
Because MATLAB creates a folder when extracting files, none of the extracted
files can overwrite files that have the same name. If you attempt to overwrite
a folder with the same name when extracting, MATLAB prompts you to
determine what you want to do.
Adding Files to a Zip Archive. To add files and folders to a zip file archive
in the Current Folder browser, do one of the following:
• Select, and then drag the file that you want to add onto the archive.
• Copy the file that you want to add to the archive. Then, select the archive
to which you want to add the file and paste the file into the archive.
If the archive contains a file or folder with the same name as the one you are
adding, a MATLAB dialog box opens. The dialog box asks if you want to
replace the existing file in the archive.
For instance:
• Right-click a zip archive, and then from the context menu select Compare
Against and specify the folder to which you want to compare the contents
of the zip archive.
• Expand a zip archive, right-click a file within it, and then from the context
menu select Compare Against. Specify the file to which you want to
compare the archived file.
6-35
6 Managing Files in MATLAB®
3 Type over the existing name with the new name. Warnings appear when:
• The new name is invalid. Change the name to make it valid. File names
must start with a letter, and can contain letters, digits, or underscores.
6-36
Creating, Opening, Changing, and Deleting Files and Folders
• The folder is on the search path. See “Handling Errors and Unexpected
Behavior When Updating Folders” on page 6-82.
4 Press Enter.
• Click to the left of an icon and drag up or down to select contiguous items
• Shift+click to select contiguous items
• Ctrl+click to select non-contiguous items
Note You cannot delete a folder while it is on the search path. See “Handling
Errors and Unexpected Behavior When Updating Folders” on page 6-82.
When you delete a file or folder using the Current Folder browser, MATLAB
permanently removes it or moves it to another location, based on your
platform.
6-37
6 Managing Files in MATLAB®
6-38
Creating, Opening, Changing, and Deleting Files and Folders
Setting the preference to delete files permanently makes delete run faster.
To override the preference when using the delete function, use the recycle
function.
The location for deleted files varies by platform, as the following table
indicates.
Deleted files remain in these locations until you remove them. To remove
deleted files, use operating system features, such as Empty Recycle Bin on
Windows platforms.
6-39
6 Managing Files in MATLAB®
Note You cannot move a folder that is on the search path using the Current
Folder browser. See “Handling Errors and Unexpected Behavior When
Updating Folders” on page 6-82
To copy and move files and folders using functions, use copyfile and
movefile.
2 From the context menu, select an option for opening or importing the file:
• Open — Opens the file using the appropriate MATLAB tool for the file type.
For example, this option loads a MAT-file into the Workspace browser.
• Open in GUIDE — Opens a FIG-file in GUIDE instead of a figure window.
For more information, see “Opening GUIDE”.
• Open as Text — Opens the file in the Editor as a text file, even if the file
type is associated with another application or tool.
6-40
Creating, Opening, Changing, and Deleting Files and Folders
This is useful, for example, if you have imported a tab-delimited data file
(.dat) into the workspace and you find you want to add a data point. Open
the file as text in the Editor, make your addition, and then save the file.
• Open Outside MATLAB — Opens the file using the application or tool
that the operating system associates with the file type.
For example, .mat is the extension for MATLAB data files and Microsoft
Access files. Whereas Open loads the file into the MATLAB workspace,
Open Outside MATLAB opens the file into Microsoft Access. See
“Managing File Associations for MATLAB on Windows Systems” on page
1-5.
For information on how to view information about a file without opening it,
see “Viewing File Details Without Opening Files” on page 6-18.
See Also.
6-41
6 Managing Files in MATLAB®
MATLAB runs the open function on your behalf to open the selected item
in the appropriate tool. Specifically:
See the open reference page for details about what action occurs if there are
name conflicts. If no action exists to work with the selected item, Open
selection calls edit.
1 In the Current Folder browser, change the current folder to the folder
containing the file to run.
3 (Optional) If you have defined a run configuration for the file you want to
use, select it from the Run Configurations on the context menu. Select
Edit Configurations to edit or create one.
If you have customized the Current Folder Browser toolbar with a Run button
, you can select the file and then click the Run button. That button has a
dropdown list of function run configurations you have defined. For details, see
“Access Frequently Used Features” on page 2-10.
6-42
Creating, Opening, Changing, and Deleting Files and Folders
1 Right-click the name of a function in the Current Folder browser and select
Run Configurations > Edit Configurations.
5 Click Close to save the configuration and exit the dialog box.
2 The function executes according to the configuration you select and that
configuration is the selected one the next time you use this context menu.
For more information about using run configurations, see “Run Functions in
the Editor”.
!vi yearlystats.m
6-43
6 Managing Files in MATLAB®
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 &
!excel.exe &
opens Microsoft Excel software and returns control to the Command Window
so you can continue running MATLAB language statements.
See the reference pages for the unix, dos, and system functions for details
about running external programs that return results and status.
6-44
Creating, Opening, Changing, and Deleting Files and Folders
getenv('PATH')
You can make modifications to the system path that persist for the current
MATLAB session or across subsequent MATLAB sessions, as described in the
sections that follow.
Modify the System Path for the Current MATLAB Session. Do one of
the following:
• Change the current folder in MATLAB to the folder that contains the
program you want to run.
• Issue these commands using the Command Window:
path1 = getenv('PATH')
path1 = [path1 ':/usr/local/bin']
setenv('PATH', path1)
!echo $PATH
If you restart MATLAB, the folder is no longer on the system path visible
to MATLAB.
Modify the System Path Across MATLAB Sessions Within the Current
Shell Session. To add a folder to the system path from the shell:
1 Stop MATLAB.
2 Depending on the shell you are using, type one of the following at the system
command prompt, where myfolder is the folder that contains the program
you want to run:
export PATH="$PATH:myfolder"
6-45
6 Managing Files in MATLAB®
3 Start MATLAB.
!echo $PATH
If you restart MATLAB within the current shell session, the folder remains
on the system path visible to MATLAB. However, if you restart the shell
session, and then restart MATLAB, the folder is no longer on the system
path visible to MATLAB.
path1 = getenv('PATH')
path1 = [path1 ':/usr/local/bin']
setenv('PATH', path1)
!echo $PATH
6-46
Comparing Files and Folders
• If you have a file open in the Editor, on the Editor tab, in the File section,
6-47
6 Managing Files in MATLAB®
If there are multiple comparison types available for your selections, you can
change what type of comparison to run. For example, text, binary, file list, or
XML comparison. To change the comparison type, create a new comparison
using the Comparison Tool. You can change comparison type in the Select
Files or Folders for Comparison dialog box.
For example, from the Current Folder browser, if you select two MAT-files to
compare, you get the default comparison type showing information about the
variables. To change the comparison type to binary, create a new comparison
6-48
Comparing Files and Folders
using the Comparison Tool. See “Selecting Files or Folders to Compare from
the Comparison Tool” on page 6-62.
• Compare lines in two text files (some other applications refer to this as a
file diff operation). See “Comparing Text Files” on page 6-53.
• Compare and merge variables in two MAT-files. See “Comparing
MAT-Files” on page 6-59.
• Determine whether the contents of two binary files match. See “Comparing
Binary Files” on page 6-61.
• Compare any combination of folders, zip files, or Simulink manifests to
determine:
- Which file and folder names are unique to each list
- If files and folders with the same name in each list have the same content
See “Comparing Folders and Zip Files” on page 6-49.
• Compare XML files:
- If you select XML files to compare and you have MATLAB Report
Generator™ software, the Comparison Tool runs a hierarchical matching
algorithm. You then see a report showing a hierarchical view of the
portions of the two XML files that differ.
- If you have Simulink Report Generator software, you can select a pair of
Simulink models (.mdl files) to compare XML files generated from them.
6-49
6 Managing Files in MATLAB®
When you use the Comparison Tool to compare two folders (sometimes
referred to as directories) or any file list comparison (for example, folder
versus zip file), a window opens and presents the contents side by side. The
tool enables you to:
For list comparisons, if you want to expand the list to see all files in subfolders
in one report, select the Include subfolders check box when selecting items
to compare. If you do not include subfolders, you can click compare links in
the report to open a new comparison of two folders with changed content.
The File and Folder Filters dialog box opens. Specify filters to ignore certain
files and folders, such as backup files or files created by a revision control
system. Filters can save time when reviewing differences, especially when
comparing many subfolders. Double-click to edit existing filters.
For example, to ignore all files and folders in a folder named CVS, open the
File and Folder Filter dialog box and enter:
CVS/
To ignore all files in a folder named CVS, but not ignore subfolders, enter:
6-50
Comparing Files and Folders
CVS/*
Highlighting of Differences
The Comparison Tool displays the contents of the lists side by side and
highlights files and subfolders that do not match. The following table
describes how the tool highlights each type of change. The status message
(such as identical or contents changed) appears in the Change Summary
column.
The following image shows an example of the Comparison Tool when two
folders are compared. The results are sorted by Type.
6-51
6 Managing Files in MATLAB®
• You can sort the results by name, type, size, or last modified timestamp by
clicking the column headers. For example, click the Type column header to
sort by folder and file type, as shown in the preceding figure.
• To open a new comparison of two files or folders with changed contents,
click the compare link next to file or folder names highlighted in pink.
• To open a file in the Editor, click the open link next to a file name.
If the file is present in both folders, you can click links to open the left
or right file.
6-52
Comparing Files and Folders
• If subfolders are very large and contain many files, analysis continues in
the background. The tool displays the number of items still to be compared
at the top of the report, as shown in the next figure. You can click the links
to Skip Current item or Cancel All to stop further analysis.
• For details on other comparison tool features, see “Using Comparison Tool
Features” on page 6-62.
Highlighting of Differences
When you use the Comparison Tool to compare two text files, a window opens
and presents the two files side by side. Symbols indicate how you can adjust
the files to make them match. This feature can be useful when you want to
compare the latest version of a text file to an autosave version.
The Comparison Tool report displays the files side by side and highlights
lines that do not match, as follows:
6-53
6 Managing Files in MATLAB®
6-54
Comparing Files and Folders
The Comparison Tool attempts to match lines and detects local text that is
added, deleted, or changed. It does not do a simple line-by-line comparison. In
the previous image, for example, the tool determines that lengthofline.m
has a line of code that does not exist in lengthofline2.m and highlights it
(line 23) in green. Also, notice that the tool takes the additional line into
6-55
6 Managing Files in MATLAB®
account and determines that the line containing the end statement in each
file matches, even though the end statement does not occur on the same line
number.
If the files you are comparing are extremely long, the tool could run out of
memory while attempting to perform the file comparison. In which case,
the message,
• Click the down arrow toolbar button to go to the next set of lines that differ.
If no additional sets of lines differ, the down arrow takes you to the end of
the file.
• Click the up arrow toolbar button to go to a previous set of lines that differ.
If no previous set of lines differ, the up arrow takes you to the beginning of
the file.
6-56
Comparing Files and Folders
Use the toolbar button, , to toggle the display of differences only involving
whitespace characters, or select Comparison > Ignore Whitespace.
Use the toolbar button, , to toggle the display of sections of the report that
do not contain any differences, or select Comparison > Show Differences
Only.
For details on other comparison tool features, see “Using Comparison Tool
Features” on page 6-62.
6-57
6 Managing Files in MATLAB®
Note Report links for opening files in MATLAB only work in the MATLAB
Web browser.
1 Open one of the text files you want to compare in the Editor.
open(fullfile(matlabroot,'help','techdoc','matlab_env',...
'examples','lengthofline.m'))
2 On the Editor tab, in the File section, click Compare. If your file is
modified, the Editor saves the file before comparing. Alternatively, under
Compare, select Save and Compare with.
Navigate to the file you want to compare against, select the file, and click
Open. To open the example file provided, select lengthofline2.m from
the folder where you found lengthofline.m.
6-58
Comparing Files and Folders
Comparing MAT-Files
Note To select files to compare, see “Select the Files or Folders to Compare”
on page 6-47.
You can use the Comparison Tool to compare two MAT-files. The tool presents
the variables in the two files side by side, which enables you to:
• View and sort by the name, size, class, and change summary of all variables.
• View details of differences between variables, to see which fields of a
structure are different, and view differences in individual elements of an
array.
• Merge changes between files by copying modified variables from one file to
the other (Caution: No undo).
• See which variables are common to each file and which are unique.
• Load the contents of the variables into the Variable Editor by clicking the
name of that variable.
• Load the MAT-files into the workspace by clicking a Load link.
• Save a copy of the report as an HTML file. Click Save As on the toolbar.
6-59
6 Managing Files in MATLAB®
Click the Merge button in the Merge column to copy modified variables
from one file to the other.
The following image shows the results when you compare two files, data1.mat
and data2.mat.
6-60
Comparing Files and Folders
Note To select files to compare, see “Select the Files or Folders to Compare”
on page 6-47.
6-61
6 Managing Files in MATLAB®
You can use the Comparison Tool to compare two binary files such as DLL
files or MEX-files. Also, you can select the Binary comparison type for any
pair of files with a choice of comparison types.
• If the files are the same, the tool displays the message: The files are
identical.
• If the files differ, the tool displays the message: The files are different.
If the files differ, you can click the Show Details link to view the binary files
and the byte offset of the first difference.
1 From the MATLAB desktop, on the Home tab, in the File section, click
Compare. Select the files or folders to compare.
6-62
Comparing Files and Folders
2 In the dialog box, select two files or folders to compare. Use the drop-down
lists to select recent comparison items, or the Browse buttons to locate
and select the items that you want to compare.
You also can drag and drop a file or folder from Windows Explorer to the
left and right file and folder fields.
3 Optionally, choose the comparison type you want to use. Either use the
default Comparison type value, or if multiple comparison types are
available, select a different one from the list. For example, for text files you
could select text or binary comparison types.
4 Click Compare.
Finding Text
To find a phrase in the current display, select Edit > Find, or click the Find
text button . The resulting Find dialog box is the same as the one you use
in the Command Window. For more information, see “Find Text in Command
Window or History” on page 3-13.
6-63
6 Managing Files in MATLAB®
visdiff(fileorfoldername1, fileorfoldername2)
visdiff('lengthofline.m', 'lengthofline2.m')
6-64
Making Files and Folders Accessible to MATLAB®
For files in @ (class) and + (package) folders, make the parent folder accessible.
For details, see “Organizing Classes in Folders”.
To understand the differences in the basic options, and for other approaches,
see “All Options for Making Files Accessible” on page 6-66.
6-65
6 Managing Files in MATLAB®
• Store the files that you and others create in the MATLAB folder, which is on
the search path. See “Locations for Storing Your Files” on page 6-4.
• Change the current folder to the folder that contains the files.
• Add the folders that contain the files to the search path.
Usage Recommendation
You seldom run the file. Change the current folder to the folder that
contains the file. See “Viewing and Changing the
Current Folder” on page 6-2.
The file is a script Use the run function.
(takes no input or
output arguments).
The files are in one Put the files in the userpath folder. See
folder. “Locations for Storing Your Files” on page 6-4.
The files are in multiple Add the folders to the search path. See “Adding
folders. Folders to the Search Path” on page 6-75.
If you regularly use the files, save the changes.
See “Saving Changes to the Search Path” on page
6-78.
The files call other files
that are in multiple 1 Determine the location of all the called files.
folders. See “Dependencies Within a Folder”.
6-66
Making Files and Folders Accessible to MATLAB®
Usage Recommendation
Some files in multiple See “Detecting and Addressing Name Conflicts”
folders have the same on page 6-69.
name.
You use files in Modify the search path in a startup.m file. See
different versions “Using the Search Path with Different MATLAB
of MATLAB or on Installations” on page 6-79.
different platforms.
Option When MATLAB Can Access the File When MATLAB Cannot
Access the File
• Dialog box
• Message: Undefined
function or method
'fileName'
• Message: Cannot find
function 'fileName'
View the file in Either or both of the following are true: Either or both of the
the Current Folder following are true:
browser. • File is in the current folder.
• File is in a subfolder of
• File does not appear dimmed in Current
the current folder, and
Folder browser, assuming the Indicate
the subfolder is not on
inaccessible files option is selected
the search path.
in “Preferences for the Current Folder
Browser” on page 6-13. • File appears dimmed
in the Current Folder
browser, assuming the
Indicate inaccessible
6-67
6 Managing Files in MATLAB®
Option When MATLAB Can Access the File When MATLAB Cannot
Access the File
• MATLAB uses the file in the current folder instead of a file in a folder
on the search path.
• MATLAB uses the file whose folder is closest to the top of the search path
instead of a file further down.
The file that MATLAB does not use is called a shadowed file. In some cases,
MATLAB warns you that a shadowed file exists.
6-68
Making Files and Folders Accessible to MATLAB®
When there are name conflicts, MATLAB follows these precedence rules:
• You use a file and get a warning about a potential name conflict.
• You get unexpected results.
Name conflicts can arise from using files that you create. Conflicts also can
arise from using:
6-69
6 Managing Files in MATLAB®
See Also
• rehash
• “Toolbox Path Caching in the MATLAB Program” on page 1-23
6-70
Using the MATLAB® Search Path
Class, package, and private folders are not on the search path. See “Files
and Folders That MATLAB Can Access” on page 6-65.
6-71
6 Managing Files in MATLAB®
Therefore, you can issue MATLAB commands that result in the use of both
the MATLAB search path and the system path. For example, if you type
dos('tasklist &') in the MATLAB Command Window, then:
2 The dos function passes 'tasklist &' to the Microsoft Windows operating
system.
3 Microsoft Windows uses the system path to locate and run tasklist.exe.
Similar behavior results when you use the MATLAB unix and system
functions or the shell escape (!). For details on using the shell escape with
MATLAB, see “Running External Commands, Scripts, and Programs” on
page 6-43.
6-72
Using the MATLAB® Search Path
When you change the search path, MATLAB uses it in the current session. To
use it in future sessions, save the changes as described in “Saving Changes to
the Search Path” on page 6-78.
1 In the Current Folder browser, right-click any file or folder, and ensure
there is a check mark next to Indicate Files Not on Path .
2 Hover the pointer over any dimmed file or folder in the Current Folder
browser to find out why it is dimmed.
The Set Path dialog box opens, listing all folders on the search path.
6-73
6 Managing Files in MATLAB®
6-74
Using the MATLAB® Search Path
Current Session Only. To add folders to the top of the search path for the
duration of the current session use the following method:
1 From the Current Folder browser, select, and then right-click the folder
or folders to add.
2 From the context menu, select Add to Path, and then select an option:
• Selected Folders
• Selected Folders and Subfolders
To add the folder that contains an Editor document to the top of the search
path:
Current and Future Sessions. To add folders to the search path for the
current session and future sessions, use the addpath function, or follow
these steps:
• Add Folder
• Add with Subfolders
3 In the Add Folder to Path dialog box, select the folder to add to the search
path, and then click Select Folder.
6-75
6 Managing Files in MATLAB®
MATLAB adds the specified folder to the top of the search path.
If you do not want the folder at the top of the search path, see “Changing the
Order of Folders on the Search Path” on page 6-77.
• To use the newly modified search path only in the current session, click
Close.
• To reuse the newly modified search path in the current session and future
sessions, click Save, and then click Close.
For details on where to save the file, see “Saving Changes to the Search
Path” on page 6-78.
• To undo your changes, click Revert, and then click Close.
• To restore the default search path, click Default, and then click Close. See
“Restoring the Default Search Path” on page 6-79.
For the Current Session Only. To remove one or more folders from the
search path:
2 From the context menu, select Remove from Path, and then select an
option:
• Selected Folders
• Selected Folders and Subfolders
To remove the folder that contains an Editor document from the search path:
Document tabs appear in the Editor only when multiple documents are
open and docked in the Editor.
6-76
Using the MATLAB® Search Path
For Current and Future Sessions. To remove folders from the search
path for the current and future sessions, use the rmpath function, or follow
these steps:
1 Open the Set Path dialog box. On the Home tab, in the Environment
section, click Set Path.
3 Click Remove.
• To use the newly modified search path only in the current session, click
Close.
• To reuse the newly modified search path in the current session and future
sessions, click Save.
For details on where to save the file, see “Saving Changes to the Search
Path” on page 6-78.
• To restore the default search path, click Default. See “Restoring the
Default Search Path” on page 6-79.
5 Click Close.
1 Open the Set Path dialog box. On the Home tab, in the Environment
section, click Set Path.
6-77
6 Managing Files in MATLAB®
3 Click one of the Move buttons, such as Move to Top. The order of the folders
changes.
If you do not save the changes, the newly modified search path remains in
effect until you end the current MATLAB session.
5 Click Close.
Note The MATLAB (userpath) folder automatically moves to the top of the
search path the next time you start MATLAB. See “Locations for Storing
Your Files” on page 6-4.
Note The MATLAB (userpath) folder automatically moves to the top of the
search path the next time you start MATLAB. See “Locations for Storing
Your Files” on page 6-4.
• Click Save in the Set Path dialog box. See “Using the Set Path Dialog
Box” on page 6-73.
• Use the savepath function.
Where to Save the Search Path File. Save the search path to the default
location, matlabroot/toolbox/local, so MATLAB can locate it.
6-78
Using the MATLAB® Search Path
If you do not have write access to the default location, MATLAB prompts you
for a different location. Choose the MATLAB startup folder.
Restoring the Default Search Path. The default search path contains
only folders provided by MathWorks.
• Click Default in the Set Path dialog box. See “Using the Set Path Dialog
Box” on page 6-73. This method also adds the userpath folder. See
“Locations for Storing Your Files” on page 6-4.
• Use the restoredefaultpath function.
See also “Recovering from Problems with the Search Path” on page 6-80.
To use your files with a new MATLAB version or with multiple versions, do
one of the following:
• For each version, add the folders containing your files to the search path.
Save the search path where that version of MATLAB can access it.
• Instead of changing the pathdef.m file, include addpath statements in the
startup.m file. Use the same startup.m file with the multiple versions
of MATLAB.
6-79
6 Managing Files in MATLAB®
• You save the search path on a Windows platform, and then try to use the
same pathdef.m file on a Linux platform.
• The pathdef.m file becomes corrupt, invalid, renamed, or deleted.
• MATLAB cannot locate the pathdef.m file.
For example, when you start MATLAB, if a message like the following
appears, it indicates a problem with the search path:
To recover from problems with the search path, try the following steps.
Proceed from one step to the next only as necessary.
a Run
which pathdef
b If you want MATLAB to use the pathdef.m file at another location, make
corrections. For example, delete the incorrect pathdef.m file and ensure
the correct pathdef.m file is in a location that MATLAB can access. See
“Where to Save the Search Path File” on page 6-78.
2 Look for and correct problems with the pathdef.m and startup.m files:
6-80
Using the MATLAB® Search Path
3 Try to correct the problem using the Set Path dialog box:
a Restore the default search path and save it. See “Using the Set Path Dialog
Box” on page 6-73. Depending on the problem, you might not be able to
open the dialog box.
b Restart MATLAB to ensure that the problem does not recur.
a Run restoredefaultpath, which sets the search path to the default and
stores it in matlabroot/toolbox/local.
b If restoredefaultpath seems to correct the problem, run savepath.
The path may be bad. Please save your work (if desired), and quit.
a Run
restoredefaultpath; matlabrc
savepath('path_to_your_startup_folder/pathdef.m')
After correcting problems with the search path, make any changes to run your
files. For example, add the userpath folder or other folders to the search path.
6-81
6 Managing Files in MATLAB®
If your task fails and the error message indicates it is because the folder
is on the search path, then:
6-82
7
Editor Preferences
Editor/Debugger Preferences
In this section...
“General Preferences for the Editor/Debugger” on page 7-2
“Editor/Debugger Display Preferences” on page 7-3
“Editor/Debugger Tab Preferences” on page 7-4
“Editor/Debugger Language Preferences” on page 7-5
“Editor/Debugger Code Folding Preferences” on page 7-8
“Editor/Debugger Autosave Preferences” on page 7-9
Preference Usage
Editor Select which editor you want the MATLAB
desktop to use when you edit a file:
• MATLAB Editor
• Text editor
7-2
Editor/Debugger Preferences
Preference Usage
Opening files in editor Select On restart open files from previous
MATLAB sessions if you want the Editor and
the files it contained during your last MATLAB
session to reopen when you restart MATLAB.
Automatic file changes Select Reload unedited files that have
been externally modified if you want the
Editor to automatically reload the version of
a file that you opened and edited outside of
MATLAB when the file currently open in the
Editor has no unsaved changes.
Select Add line termination at end of
file to have MATLAB add a new empty line
(sometimes referred to as a <CR>) to the end of
a file automatically if the last line in the file
is not empty.
Preference Usage
General display option Select Highlight Current Line and select a
color to highlight the row with the cursor (also
called the caret).
Select Show line numbers to display line
numbers along the left edge of the Editor
window.
Select Enable data tips in edit mode to
display data tips when you are editing a
MATLAB code file. (Data tips are always
enabled in debug mode.)
7-3
7 Editor Preferences
Preference Usage
Option Usage
Tab size Specify the amount of space inserted when you
press the Tab key.
When you change the Tab size, it changes the
tab size for existing lines in that file, unless
you also select Tab key inserts spaces.
Indent size Specify the indent size for smart indenting.
Smart indenting is one of the “Editor/Debugger
Language Preferences” on page 7-5.
7-4
Editor/Debugger Preferences
Option Usage
Tab key inserts spaces Select to insert a series of spaces when you
press the Tab key. Otherwise, a tab acts as one
space whose length is equal to the Tab size.
Emacs-style Tab key smart indenting Specifies an indenting style similar to the style
that the Emacs editor uses.
Lines indent according to smart indenting
preferences when you position the cursor in a
line or select a group of lines, and then press
the Tab key.
Smart indenting is one of the “Editor/Debugger
Language Preferences” on page 7-5.
If you select this preference, you cannot insert
tabs within a line.
7-5
7 Editor Preferences
Preference Usage
Language Select the language for which you want to set
preferences.
Syntax highlighting Select Enable syntax highlighting to have the
Editor use different colors for different language
constructs. Then, adjust the colors you want to use
for each language element.
Access color options for the MATLAB language by
clicking Set syntax colors.
For all other languages, color options appear under
Enable syntax highlighting.
For details, see “Syntax Highlighting” on page 3-23.
Variable and function renaming Select Enable automatic variable and function
renaming to have MATLAB prompt you to rename
MATLAB Language only
all instances of a function or variable in a file when
you rename a function or variable.
7-6
Editor/Debugger Preferences
Preference Usage
7-7
7 Editor Preferences
Preference Usage
For examples and detailed information about code folding, see “Code Folding
— Expand and Collapse Code Constructs”.
Option Usage
Enable Code Folding Specifies whether you want code folding
enabled for the programming constructs that
have their corresponding Enable check box
selected.
Enable Specifies whether you want code folding
enabled for the corresponding Programming
Construct.
7-8
Editor/Debugger Preferences
Option Usage
Preference Usage
Enable autosave in the MATLAB Editor Select to have MATLAB automatically save a
copy of the files you are currently editing.
Save options Save every n minutes specifies how often you
want MATLAB to save a copy of the file you
are editing.
Save untitled files saves a copy of new,
untitled, files to Untitled.asv.
When there is more than one untitled file,
each additional file is saved to Untitledn.asv
(where n is an integer value).
For details, see “Autosaving Files”.
Close options Automatically delete autosave files directs
MATLAB to delete the autosave file when you
close the source file in the Editor.
7-9
7 Editor Preferences
Preference Usage
File name Select the naming convention you want
MATLAB to use for autosave files. For
example:
7-10
Code Analyzer Preferences
Option Usage
Enabled Integrated Warning and Error Specify whether you want to display Code
Messages Analyzer message indicators, such as the
underlining of code and the message indicator
bar, for documents open in the Editor.
For more information, see “Automatically
Check Code in the Editor — Code Analyzer”.
Underlining Specify the type of coding issues that you want
to have underlined.
Regardless of the underlining menu option you
choose, the Editor marks errors and warnings
in the message indicator bar.
Autofix Provides a link to a preference panel that
enables you to adjust the color highlighting
errors and warnings that MATLAB can autofix.
You trigger autofix by clicking the Fix button
in a Code Analyzer message.
7-11
7 Editor Preferences
Option Usage
Active Settings Select the set of message settings to use.
Click the down arrow to select or browse to a
previously saved settings file.
Actions button Click to open a menu that enables you to select:
Note If you do not have the MATLAB Compiler™ installed, the Code
Analyzer preferences pane does not display the MATLAB Compiler
(deployment) messages category.
7-12
Code Analyzer Preferences
7-13
7 Editor Preferences
In a given category Click the down arrow to the right You want to review messages
of the search field, click Show that describe coding practices
Messages in Category, and that make it difficult for others to
then click the category you want. use your code.
Click the down arrow to the
right of the search field, select
Show Messages in Category,
and then select Aesthetics and
Readability.
Click the messages that appear
as links for more information.
Not all messages appear as links.
That are warnings Click the down arrow to the right You recall previous warnings
of the search field, and then that your code generated, but you
select Show All Warnings. An cannot remember enough details
exclamation point in a yellow to use the search field to find it.
triangle indicates a warning You want to skim all the warning
message. messages to find a particular one
of interest.
7-14
Code Analyzer Preferences
To display Code Analyzer error messages that contain the string variable
and are disabled:
1 Click the down arrow in the search field, and then select Show All Errors.
2 At the end of the string severity:error, press the Space key, and then
type variable.
3 Click the down arrow in the search field and select Show Disabled
Messages.
7-15
7 Editor Preferences
To restore the list of all messages, click the clear search button .
7-16
8
Internationalization
To see what your current settings are, use the instructions in “Setting Locale
on Windows Platforms” on page 8-4, “Setting Locale on Linux Platforms” on
page 8-7, or “Setting Locale on Macintosh Platforms” on page 8-8. For more
information, “Troubleshooting I18n Messages and Settings” on page 8-9.
8-2
How the MATLAB® Process Uses Locale Settings
8-3
8 Internationalization
1 Select Start -> Control Panel -> Clock, Language, and Region ->
Regional and Language.
Note The user locale and system locale must be the same value on the
Microsoft Windows platform.
8-4
Setting the Locale
1 Select Start -> Control Panel -> Clock, Language, and Region ->
Regional and Language.
5 Select a target locale from the Current system locale: drop-down list.
Note When you change the system locale, you must reboot your system;
otherwise, you might see unexpected locale-setting behaviors.
1 Select Start -> Control Panel -> Regional and Language Options.
Note The user locale and system locale must be the same value on the
Microsoft Windows platform.
1 Select Start -> Control Panel -> Regional and Language Options.
8-5
8 Internationalization
Note When you change the system locale, you must reboot your system;
otherwise, you might see unexpected locale-setting behaviors.
1 Select Start -> Control Panel -> Regional and Language Options.
Note The user locale and system locale must be the same value on the
Microsoft Windows platform.
1 Select Start -> Control Panel -> Regional and Language Options.
Note When you change the system locale, you must reboot your system;
otherwise, you might see unexpected locale-setting behaviors.
8-6
Setting the Locale
Use the LC_ALL environment variable to over-write all locales specified with
other environment variables. If a single locale has to be set to all locale
categories, use LANG instead of LC_ALL.
To configure, make a symbolic link between your font and the MATLAB font
fallback directory. For example, to use the Kochi font, at the Linux system
prompt type:
ln -s /usr/share/fonts/truetype/kochi
8-7
8 Internationalization
matlabroot/sys/java/jre/glnxa64/jre/lib/fonts/fallback
Setting UI Language
8-8
Troubleshooting I18n Messages and Settings
In this section...
“Asian Characters Incorrectly Displayed on Linux Systems” on page 8-9
“Characters Incorrectly Displayed on Windows Systems” on page 8-10
“datenum Might Not Return Correct Value” on page 8-10
“Numbers Display Period for Decimal Point” on page 8-10
“MATLAB Displays Messages in English” on page 8-11
“File or Folder Names Incorrectly Displayed” on page 8-11
To configure, make a symbolic link between your font and the MATLAB font
fallback directory. For example, to use the Kochi font, at the Linux system
prompt type:
ln -s /usr/share/fonts/truetype/kochi
matlabroot/sys/java/jre/glnxa64/jre/lib/fonts/fallback
8-9
8 Internationalization
For example, look at the modification date of your MATLAB license.txt file:
cd(matlabroot)
f=dir('license.txt')
f =
name: 'license.txt'
date: '10-May-2007 17:48:22'
bytes: 5124
isdir: 0
datenum: 7.3317e+005
If your code uses the date field of the dir command, similar to:
n=datenum(f.date);
n=f.datenum;
8-10
Troubleshooting I18n Messages and Settings
The MATLAB language reserves the use of commas to the cases described in
the “Comma — ,” topic of the Programming Fundamentals Symbol Reference.
8-11
8 Internationalization
8-12
Index
Index-1
Index
Index-2
Index
Index-3
Index
viewing 6-14 L
history license information 4-16
automatic log file 1-20 license management 2-47
history file 3-29 line wrapping 3-19
history of statements 3-29 log
history.m file 3-29 automatic 1-20
hot keys 2-15 file 1-20
desktop 2-15 statements 3-29
Variable Editor 5-8 logfile startup option 1-20
HTML viewer in MATLAB 2-42 login
remote on Macintosh 1-7
I
image files M
previewing in Current Folder Browser 6-18 Macintosh
import startup
files for use with MATLAB 6-71 remote login 1-7
include MAT-files
files with MATLAB 6-71 comparing 6-59
indenting compatibility 2-56
in Command Window 3-23 compression options 2-56
initiation (init) file for MATLAB 1-19 creating 5-9
Internet defined 5-9
proxy server settings 2-44 2-67 preferences 2-56
updating using Current Folder Browser 6-32
J viewing variables without loading 6-18
matched delimiters
Java Heap
preferences 3-21
preferences 2-59
matching parentheses
Java VM
in Editor 3-21
starting without 1-21
MATLAB
exiting 1-7
K confirmation 1-8
keyboard shortcuts search path 6-71
Command Window 2-15 MATLAB code files
Variable Editor 5-8 file association (Windows) 1-3
keywords running
color indicators 2-8 at startup 1-21
matching in Editor 3-21 matlab folder 1-13
MATLAB installations
Index-4
Index
Index-5
Index
Index-6
Index
Index-7
Index
Index-8