MATLAB Desktop Tools and Development Environment
MATLAB Desktop Tools and Development Environment
R2016b
How to Contact MathWorks
Phone: 508-647-7000
v
userpath as Initial Working Folder . . . . . . . . . . . . . . . . . . 1-17
Changing the Startup Folder . . . . . . . . . . . . . . . . . . . . . . . 1-18
Desktop
2
Change Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Font Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Help and Web Browser Fonts . . . . . . . . . . . . . . . . . . . . . . . . 2-3
Adding Fonts on Windows Systems . . . . . . . . . . . . . . . . . . . . 2-3
vi Contents
Define Keyboard Shortcuts . . . . . . . . . . . . . . . . . . . . . . . . . . 2-15
Keyboard Shortcuts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-15
Choose a Set of Keyboard Shortcuts . . . . . . . . . . . . . . . . . . 2-15
Compare Sets of Keyboard Shortcuts . . . . . . . . . . . . . . . . . 2-18
Display Keyboard Shortcuts . . . . . . . . . . . . . . . . . . . . . . . . 2-19
Customize Keyboard Shortcuts . . . . . . . . . . . . . . . . . . . . . . 2-22
Evaluate and Resolve Keyboard Shortcut Conflicts . . . . . . . 2-27
Examples of Creating, Modifying, and Deleting Keyboard
Shortcuts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-29
Delete a Set of Keyboard Shortcuts . . . . . . . . . . . . . . . . . . . 2-32
Use Keyboard Shortcuts Settings Files Created on Other
Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-33
Keyboard Shortcut Restrictions . . . . . . . . . . . . . . . . . . . . . . 2-33
Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-48
Set Preferences for MATLAB . . . . . . . . . . . . . . . . . . . . . . . 2-48
Where MATLAB Stores Preferences . . . . . . . . . . . . . . . . . . 2-49
Preferences MATLAB Uses When Multiple Releases Are
Installed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-49
General Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-51
Confirmation Dialog Boxes Preferences . . . . . . . . . . . . . . . . 2-52
Source Control Preferences . . . . . . . . . . . . . . . . . . . . . . . . . 2-54
vii
Keyboard Shortcuts Preferences . . . . . . . . . . . . . . . . . . . . . 2-54
Colors Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-55
Colors Programming Tools Preferences . . . . . . . . . . . . . . . . 2-56
Comparison Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-57
Toolbars Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-58
Entering Commands
3
Enter Statements in Command Window . . . . . . . . . . . . . . . . . 3-2
viii Contents
Command History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28
What Is the Command History? . . . . . . . . . . . . . . . . . . . . . 3-28
Use Command History Commands . . . . . . . . . . . . . . . . . . . 3-29
Change the Command History Date Format . . . . . . . . . . . . 3-30
Command History Preferences . . . . . . . . . . . . . . . . . . . . . . 3-30
ix
View Variable Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
Edit Variable Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
Navigate Variable Contents . . . . . . . . . . . . . . . . . . . . . . . . 5-10
Copy, Rename, and Delete Variables . . . . . . . . . . . . . . . . . . 5-11
Delete Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-12
Display Statistics in the Workspace Browser . . . . . . . . . . . . 5-13
x Contents
Files and Folders You Should Add to the Search Path . . . . . 6-29
When Multiple Files Have the Same Name . . . . . . . . . . . . . 6-30
Locations of MathWorks Products . . . . . . . . . . . . . . . . . . . . 6-30
xi
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 Backup Files Preferences . . . . . . . . . . . . . . 7-9
Editor/Debugger Autoformatting Preferences . . . . . . . . . . . 7-10
Add-Ons
8
Get Add-Ons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Install an Add-On Manually . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Internationalization
9
Locale Settings for MATLAB Process . . . . . . . . . . . . . . . . . . . 9-2
Default Locale Setting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-3
Supported Character Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-3
Platform-Specific Localized Formats for Current Folder
Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-3
xii Contents
Set Locale on Windows Platforms . . . . . . . . . . . . . . . . . . . . . . 9-5
Locale on Windows 10 Platforms . . . . . . . . . . . . . . . . . . . . . . 9-5
Locale on Windows 8 Platforms . . . . . . . . . . . . . . . . . . . . . . 9-5
Locale on Windows 7 Platforms . . . . . . . . . . . . . . . . . . . . . . 9-6
xiii
1
After starting MATLAB, the desktop opens. Desktop components that were open when
you last shut down MATLAB are opened on startup. You can specify other startup
options, such the initial working folder—for more information, see “Specify Startup
Options” on page 1-21 and “MATLAB Startup Folder” on page 1-16.
1-2
Start MATLAB on Windows Platforms
For information about this program, including information about how to modify
the configuration, see Start the License Manager in the “License Management”
documentation.
1-3
1 Startup and Shutdown
By default, MATLAB associates the latest installed version to MATLAB file types. If
you use the Windows file manager or the Control Panel to associate a MATLAB version
to a file type, that version remains associated with the file type even when you install
another MATLAB. If, instead, you always want to use the latest MATLAB version, you
must manually reassociate the type with each new installation of MATLAB. If you want
to return to the default behavior, uninstall every MATLAB that is manually associated to
any MATLAB file type. Then reinstall the latest MATLAB release.
Sometimes double-clicking a MATLAB file in the Windows file manager opens a new
instance of the version of MATLAB that is already open. To work around this issue,
uninstall versions of MATLAB, release R2010a or earlier. Then reinstall MATLAB
R2010b or later.
More About
• “MathWorks File Extensions” on page 6-28
• “Associate .mat Files with MATLAB” on page 1-5
1-4
Associate .mat Files with MATLAB
1 Open the Windows Control Panel. The Control Panel is typically available from
the Windows Start menu, or refer to your Windows documentation.
2 From View by: Category, select Programs.
3 Select Default Programs.
4 Select Set your default programs. The Programs pane shows installed versions
of MATLAB, R2010b and later.
5 Select a MATLAB release, then Choose defaults for this program.
6 Check the box next to the .mat entry.
7 Select Save.
8 Close all dialog boxes and menus, and exit the Control Panel.
If you want to use MATLAB R2010a or earlier, choose the Associate a file type or
protocol with a program options from the Default Programs menu instead. Scroll
down the list of file types to the .mat entry. Select Change Program... and choose a
version of MATLAB from the Recommended Programs list. Do not use the Browse
button.
For information about using these options, see your Windows documentation.
Note: By default, MATLAB associates the latest installed version to MATLAB file types.
However, once you use the Windows Control Panel or the file manager to associate a
MATLAB version to a file type, you must manually reassociate the type with each new
installation of MATLAB. If you want to return to the default behavior, uninstall every
MATLAB that is manually associated to any MATLAB file type. Then reinstall the latest
MATLAB release.
More About
• “Associating Files with MATLAB on Windows Platforms” on page 1-4
1-5
1 Startup and Shutdown
If you did not set up symbolic links in the installation procedure, type matlabroot/
bin/matlab, where matlabroot is the name of the folder in which you installed
MATLAB.
After starting MATLAB, the desktop opens. Desktop components that were open when
you last shut down MATLAB are opened on startup.
If the DISPLAY environment variable is not set or is invalid, the desktop does not display.
If you have trouble starting MATLAB, see “Troubleshooting Installation” topics in the
Installation Guide.
You can specify the initial working folder and other options — for more information,
see “MATLAB Startup Folder” on page 1-16 and “Specify Startup Options” on page
1-21.
To execute a MATLAB script, for example hello.m, via a remote ssh login, at the
command shell type:
ssh local.foo.com matlab -nodisplay -nojvm < hello.m
The ssh command pipes hello.m to MATLAB running on the remote host,
local.foo.com. The -nodisplay option starts MATLAB without the desktop.
See Also
matlab (Linux)
1-6
Start MATLAB on Mac Platforms
The desktop opens, including components that were open when you last shut down
MATLAB.
MATLAB automatically adds the userpath folder to the top of its search path.
If MATLAB fails to start due to a problem with required system components such as
Java® software, diagnostics run automatically and advise you of the problem, with
suggestions to correct it.
where matlabroot is the name of the folder in which you installed MATLAB, and
Release is your MATLAB release number, for example, R2013b.
Start MATLAB.
./matlab
1-7
1 Startup and Shutdown
The desktop opens, including components that were open when you last shut down
MATLAB.
MATLAB automatically adds the userpath folder to the top of its search path.
If MATLAB fails to start due to a problem with required system components such
as Java software, diagnostics run automatically and advise you of the problem, with
suggestions to correct it.
See Also
matlab (Mac)
More About
• “MATLAB Startup Folder” on page 1-16
• “Troubleshooting Installation”
1-8
Exit MATLAB
Exit MATLAB
In this section...
“Ways to Exit” on page 1-9
“Confirm Exiting” on page 1-9
“Running a Script When Exiting” on page 1-10
Ways to Exit
At any time, do one of the following:
Confirm Exiting
To set a preference that displays a confirmation dialog box when you exit:
MATLAB then displays the following dialog box when you exit.
1-9
1 Startup and Shutdown
You can also display your own exit confirmation dialog box using a finish.m script, as
described in the following section.
See Also
exit | finish | quit
More About
• “Confirmation Dialog Boxes Preferences” on page 2-52
• “Recovering Data After an Abnormal Termination” on page 1-11
• “Error Log Reporting” on page 1-12
• “When MATLAB Terminates Unexpectedly” on page 1-13
1-10
Recovering Data After an Abnormal Termination
• Use the Command History or the file on which it is based, history.m, to run
statements from the previous session. You might be able to recreate data as it was
before the termination.
• If you used the diary function or -logfile startup option for the session in which
MATLAB terminated unexpectedly, you might be able to recover output.
• If you saved the workspace to a MAT-file during the session, you can recover it by
loading the MAT-file.
• If you were editing a file in the Editor when MATLAB terminated unexpectedly, and
you had the backup feature enabled, you should be able to recover changes you made
to files you had not saved. To recover, open the file in the Editor.
• If you were in a Simulink® session when a segmentation violation occurred, and you
have the Simulink Autosave Options preference selected, the last autosave file for
the model reflects the state of the autosave data before the segmentation violation.
Because Simulink models might be corrupted by a segmentation violation, a model
is not autosaved after a segmentation violation occurs. To recover the file, open the
model.
See Also
diary | load | save
Related Examples
• “Save and Load Workspace Variables” on page 5-15
• “Save Files”
More About
• “Commonly Used Startup Options” on page 1-19
1-11
1 Startup and Shutdown
Copy the contents of the file into the body of an email message and send to
[email protected]. After you send the log file, delete it or move it to another location.
If you do not delete it, the Error Log Reporter might detect it on the next startup and
prompt you to send it, even if you already did.
See Also
tempdir
1-12
When MATLAB Terminates Unexpectedly
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.
2 Click Close to terminate MATLAB.
3 Restart MATLAB. If the Error Log Reporter dialog box opens, select the option to
send a report to MathWorks.
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.
2 Click Attempt to Continue. MATLAB tries to return to the Command Window or
tool you were using.
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.
1-13
1 Startup and Shutdown
A java.opts file in this location applies to all users, but individual users might not
have permissions to modify files there.
• To enable the use of the Java debugger, use the matlab -jdb command. For
information, see matlab (Linux) or matlab (Mac).
• To adjust the Java heap size on desktop versions of MATLAB, use “Java Heap
Memory Preferences”.
• To modify the static Java class path, create a javaclasspath.txt file. For
information, see “Static Path”.
To modify the library path, create a javalibrarypath.txt file. For information, see
“Locating Native Method Libraries”.
See Also
matlab (Linux) | matlab (Mac)
Related Examples
• “Java Heap Memory Preferences”
• “Static Path”
• “Locating Native Method Libraries”
1-14
Specifying Java Startup Options
More About
• “MATLAB Startup Folder” on page 1-16
1-15
1 Startup and Shutdown
Note: If a startup.m file changes the current folder, this value overrides the initial
working folder value. Do not add cd statements to startup.m. For more information
about user-defined options, see startup.
In this section...
“Default Folder on Windows Platforms” on page 1-16
“Default Folder on Mac Platforms” on page 1-17
“Default Folder on Linux Platforms” on page 1-17
“userpath as Initial Working Folder” on page 1-17
“Changing the Startup Folder” on page 1-18
1-16
MATLAB Startup Folder
To specify the userpath as the startup folder, set the value of the environment variable
MATLAB_USE_USERWORK to 1 before 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.
• You can store the MATLAB files you work with in one, appropriately named location,
such as Documents/MATLAB.
• Your MATLAB files are readily available at startup, because the current folder is
always the same.
• You can always run your files because MATLAB automatically adds the userpath
folder to the top of the search path.
• The first time you run a new version of MATLAB, MATLAB automatically creates the
userpath folder if it does not exist.
1-17
1 Startup and Shutdown
By default, the initial working folder is set to Location based on MATLAB startup
rules.
See Also
startup | userpath
Related Examples
• “Specify Startup Options” on page 1-21
• “Assign userpath as Startup Folder (Macintosh or UNIX)” on page 6-51
More About
• “General Preferences” on page 2-51
• “Determine If Files and Folders Are on the Search Path” on page 6-42
1-18
Commonly Used Startup Options
1-19
1 Startup and Shutdown
See Also
matlab (Linux) | matlab (Mac) | matlab (Windows)
1-20
Specify Startup Options
On Windows platforms, you can precede a startup option with either a hyphen (-) or a
slash (/). For example, -nosplash and /nosplash are equivalent.
To use startup options for the MATLAB shortcut icon on a Windows platform, follow
these steps:
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.
This example runs the MATLAB results script or function after startup, where
results.m is in the startup folder or on the MATLAB search path. The text in the
Target field is similar to the following:
1-21
1 Startup and Shutdown
Include the statement, but not the option (-r) in double quotation marks.
Use semicolons or commas to separate multiple statements. This example changes the
format to short, and then runs the MATLAB code file results:
Separate multiple options with spaces. This example starts MATLAB without displaying
the splash screen, and then runs the MATLAB code file results:
To change the current folder on startup to mytools, set the Initial working folder
value, described in “General Preferences” on page 2-51, to:
/home/myname/mytools
At startup, MATLAB automatically executes the file matlabrc.m and, if it exists on the
MATLAB search path, startup.m. The file matlabrc.m, which is in the matlabroot/
toolbox/local folder, is reserved for use by MathWorks and by system administrators
on multiuser systems. To locate the startup.m file, type:
which startup
1-22
Specify Startup Options
function test(x)
To pass a Perl variable instead of a constant as the input parameter, follow these steps.
This command starts MATLAB and runs test with the input argument 10.
For more information, see the -r option in matlab (Windows), matlab (Mac), or
matlab (Linux).
For information about memory allocation for Java objects, see “Java Heap Memory
Preferences”.
See Also
matlab (Linux) | matlab (Mac) | matlab (Windows)
More About
• “Commonly Used Startup Options” on page 1-19
1-23
1 Startup and Shutdown
In this section...
“About Toolbox Path Caching in MATLAB” on page 1-24
“Using the Cache File Upon Startup” on page 1-24
“Updating the Cache and Cache File” on page 1-24
“More Diagnostics with Toolbox Path Caching” on page 1-26
MATLAB does not use the cache file at startup if you clear the Enable toolbox path
cache check box in General Preferences. Instead, it creates the cache by reading from
the operating system folders, which is slower than using the cache file.
MATLAB caches (essentially, stores in a known files list) the names and locations of files
in matlabroot/toolbox folders. These folders are for files provided with MathWorks
products that should not change except for product installations and updates. Caching
those folders provides better performance during a session because MATLAB does not
actively monitor those folders.
1-24
Toolbox Path Caching in MATLAB
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 might
be overwritten when you install a new version of MATLAB.
When you add files to matlabroot/toolbox folders, the cache and the cache file need
to be updated. MATLAB updates the cache and cache file automatically when you install
toolboxes or toolbox updates using the installer for MATLAB. MATLAB also updates the
cache and cache file automatically when you use MATLAB tools, such as when you save
files from the MATLAB Editor to matlabroot/toolbox folders.
When you add or remove files in matlabroot/toolbox folders by some other means,
MATLAB might not recognize those changes. For example, when you:
Update the cache so MATLAB recognizes the changes you made in matlabroot/
toolbox folders.
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
Change Fonts
In this section...
“Font Preferences” on page 2-2
“Help and Web Browser Fonts” on page 2-3
“Adding Fonts on Windows Systems” on page 2-3
Font Preferences
Change the font for desktop tools using the Fonts Preferences dialog box. Access this
dialog box on the Home tab, in the Environment section, by clicking Preferences.
Select MATLAB > Fonts.
The default font that MATLAB uses for a particular tool depends upon its content:
• Code tools, such as the Command Window and Editor, use a monospaced font to
preserve vertical alignment.
• Text-based tools, such as the Current Folder browser, use your system’s font.
• A few specific tools, including the Profiler, use a custom proportional font.
You can change the font for the group of code tools, for the group of text-based tools, or
for individual tools. To change the font for an individual tool, or to move a tool from one
group to another, click Custom Fonts and set the preferences for that tool.
This table describes the factory defaults for each group of tools. Refer to this table to
restore fonts to their original state.
Command Window
Workspace browser
Variables editor
2-2
Change Fonts
Note: For the Profiler, you can change the font type and size, but not the style (for
example, bold or italic).
If, during a MATLAB session, you install a font that MATLAB can use, restart MATLAB
to include it in the list. A common reason to install additional fonts is to read files created
in different languages. For details on adding fonts to your system, refer to the Microsoft
Windows help.
If MATLAB cannot display a particular font, it excludes that font from the list. The
criteria for compatible fonts are as follows:
• For desktop components (such as the Command Window), figure windows, and
uicontrols — Fonts compatible with TrueType and Microsoft OpenType® fonts
1. UNIX is a registered trademark of The Open Group in the United States and other countries.
2-3
2 Desktop
• For graphics objects, such as xlabel, ylabel, title, and text — TrueType and
Microsoft OpenType fonts
• The operating system's standard location (see your system administrator for details)
• The /jre/lib/fonts folder where Java software is installed on your system
Related Examples
• “Set Print Options” on page 2-36
2-4
Fonts Custom Preferences
On the Home tab, in the Environment section, click Preferences. Select MATLAB
> Fonts > Custom, and then set options as described in this table:
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 type, style, and size you specify in the fields.
For the Profiler, you can change the font type and size, but
changes to the font style (for example, bold or italic) have no
effect.
2-5
2 Desktop
Note: The colors you specify also apply to the Import Wizard, but do not apply to the
Help display pane or the web browser.
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 Syntax Highlighting sample and Command
Window sample areas in the dialog box update to show you how it looks.
Tip If you use a gray background color, a selection in an inactive window is not
visible.
4 Click OK.
2-6
Change Color Settings
syntax highlighting, helps you to identify syntax elements, such as if/else statements
at a glance. The Editor also provides syntax highlights colors for other languages.
In the Command Window, only the MATLAB input you type is highlighted. The output
from running MATLAB functions is not highlighted.
• 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.
When you choose a color, the Command Window sample area in the dialog box
updates to show you how it looks.
3 Click OK.
2-7
2 Desktop
• 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 a 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.
Clear Autofix highlight if you do not want autofix highlights to appear in the
Editor; select Autofix highlight if you do.
4 Click Apply.
5 Decide if you want to change the color that the Code Analyzer uses for errors.
In addition to changing the color of Code Analyzer indicators for errors, this
action also changes the color for errors in the Command Window, Command
History window, Editor, and Shortcuts callback area.
6 Click OK.
For more information, see “Automatically Check Code in the Editor — Code Analyzer”.
2-8
Access Frequently Used Features
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.
To add, remove, or arrange buttons on the quick access toolbar, follow these steps:
1 On the Home tab, in the Environment section, click Preferences. Then, select
MATLAB > Toolbars.
2 From the Toolbar drop-down menu, select Quick Access.
The controls for the selected toolbar appear in the Layout and Controls sections of
the Toolbars Preferences pane.
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 controls and separator bars on the selected toolbar, by
doing either of the following:
For instance, to move the MATLAB desktop Cut icon to the beginning of the
toolbar, select the Cut icon , and then click .
2-9
2 Desktop
2-10
Optimize Desktop Layout for Limited Screen Space
Desktop Layout
You can close, minimize, and undock desktop tools to optimize the desktop layout. Once
you design a layout you like, you can save it for reuse.
This table shows how you can optimize the MATLAB desktop layout on your screen.
Action Procedure
Minimize or restore the MATLAB
At the upper right corner of the Toolstrip, click
Toolstrip
or .
Open or hide a tool On the Home tab, in the Environment section,
click Layout. Then, under Show, select, or clear
desktop tools you want to show or hide.
2-11
2 Desktop
Action Procedure
Use a minimized tool Click the button for the tool to open the tool
temporarily on the desktop. When you finish using
the tool, click another tool.
Restore a tool as it appeared before Do one of the following:
maximizing or minimizing
• Double-click the title bar of the maximized tool,
or the button of the minimized tool.
• On the title bar of the tool, click , and then
select Restore.
• Click the Restore button on the title bar in
that tool.
Move a tool Drag a tool by its title bar to a new location. The
status bar indicates where the tool moves if you
release the mouse.
Close a tool On the title bar of a docked tool, click , and then
select Close.
Show or hide title bars On the Home tab, in the Environment section,
click Layout. Then, under Show, select, or clear
Panel Titles.
Show or hide a toolbar in a figure From the View menu, select the toolbar of interest.
window
Undock tools to move them outside Do one of the following:
the desktop
• Drag a tool by its title bar to a new location
outside of the MATLAB desktop.
• On the title bar of the tool, click , and then
select Undock.
Move undocked tools back to the At the upper right of the tool panel, click , and
desktop then select Dock.
2-12
Optimize Desktop Layout for Limited Screen Space
Action Procedure
Manage a desktop arrangement On the Home tab, in the Environment section,
click Layout, and then select an option.
• Save an arrangement
• Use an arrangement
Note: MATLAB stores the arrangements you
• Rename or delete a saved
save as XML files in the preferences folder for
arrangement
MATLAB. The layout last used in a session is
MATLABDesktop.xml. The MATLABDesktop.xml
file loads when you start MATLAB and is
overwritten when you close MATLAB.
When you end a session, MATLAB saves the current desktop arrangement. The next
time you start MATLAB, the desktop appears as you left it. However, tools such as the
Help browser, web browser, and Variables editor do not reopen automatically, even if
they were open when you ended the last session. You can use startup options to specify
tools that you want to open on startup. For more information, see “Specify Startup
Options” on page 1-21.
Document Layout
When you open MATLAB documents, they open in the associated tool, such as the Editor
or Variables editor. 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 within a tool.
Action Procedure
Move or hide document tabs On the View tab, in the Document Tabs
section, click Tabs Position , and then
select an option.
Reorder documents Drag a document tab to a different position.
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.
2-14
Define Keyboard Shortcuts
Keyboard Shortcuts
To access desktop features quickly, 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
The following table lists the keyboard shortcuts settings files installed with MATLAB.
Browse to use a keyboard shortcuts settings file that is on your system, but not an
Active settings choice in the Keyboard Shortcuts Preferences dialog box. This situation
typically arises when you copy a settings file from another system to a folder other than
the prefdir folder. To browse to a settings file and make it your active settings file,
follow these steps:
2-16
Define Keyboard Shortcuts
The settings file you selected in step 4 is now the active settings file for MATLAB.
Future MATLAB sessions provide this settings file as a choice in the Active settings
drop-down menu.
Download keyboard shortcut settings files from File Exchange when you want to do
either of the following:
• 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.
1 Search the File Exchange Web site for the keyboard shortcut set that you want to
use. Files tagged with keyboard shortcuts configurable include:
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.
5 In the Current Folder browser, expand the newly created folder, and then double-
click the settings file you want to use.
2-17
2 Desktop
A keyboard key icon preceding a file name indicates a valid keyboard shortcut
settings file.
6 In the Keyboard Shortcuts Preferences dialog box, review the settings, and then click
OK.
MATLAB 7.9 made keyboard shortcuts consistent across the desktop. Therefore, you
might find that shortcuts you used before Version 7.9 are different.
• See how a set of keyboard shortcuts you found on File Exchange differs from your
current set of keyboard shortcuts.
• See how a set of keyboard shortcuts differs from the default set.
When you compare keyboard shortcut sets, they appear in the Comparison Tool as
follows:
• One set displays on the left side of the tool and the other set displays on the right side
of the tool.
2-18
Define Keyboard Shortcuts
• 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-19
2 Desktop
You can copy all the keyboard shortcuts from a keyboard shortcuts set and paste them
in a text file or spreadsheet application, such as Microsoft Excel®. To create a list of
keyboard shortcuts for easy browsing and future reference, follow these steps:
If no keyboard shortcut appears on the menu, one does not currently exist for that action.
To create a keyboard shortcut for an action, follow the steps in “Customize Keyboard
Shortcuts” on page 2-22.
To identify a keyboard shortcut when there is no menu option for an action, use the
Keyboard Shortcuts Preferences pane:
2-20
Define Keyboard Shortcuts
3 Narrow the list of Action names that the preferences pane displays by adding text
to describe the action. For example, add clear, if you want to find the keyboard
shortcut for clearing selected text in the Editor. Keep the description text short to
increase the likelihood of the filter returning the action you seek.
2-21
2 Desktop
4 Select the action name of interest. In this example, select Clear Selection.
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.
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-15.
2-22
Define Keyboard Shortcuts
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-25.
4 Click the Add button .
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-26.
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.
7 Evaluate and resolve any conflicts, indicated by the informational and error
icons.
For more information, see “Evaluate and Resolve Keyboard Shortcut Conflicts” on
page 2-27.
2-23
2 Desktop
8 Click Apply.
If you modify keyboard shortcuts, and then decide you do not want to keep the changes,
you can restore the default shortcuts. To restore the default state of a keyboard shortcut:
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-24) 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 name of the default set
appended with the text (modified). For instance, Windows default (modified).
• Share a keyboard shortcuts settings file with others.
2-24
Define Keyboard Shortcuts
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. Select MATLAB > Keyboard >
Shortcuts.
2 Click the Actions button , and then select Save As.
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.
Use the filter field to see the list of actions for which you can customize or define a
keyboard shortcut:
MATLAB displays only the action names or desktop menus that contain the text
you specify.
• The name of a desktop tool or menu, for example, File or Command Window.
MATLAB displays a list of the action names associated with the tool or menu you
specify. In addition, the list includes any action names that contain the name of
the tool or menu. For example, if you specify Command History, the list of action
names includes Next History Command, which is a Command Window action.
• A keyboard shortcut, for example, Ctrl+R
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.
2-25
2 Desktop
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.
2 Verify that an Action name performs the action you expect:
a Hover the mouse pointer over the Action name. For example, Remove Next
Word.
b View the tooltip that appears.
A keystroke can be a single key or the combination of a modifier (Alt, Shift, or Ctrl)
and another key. When you create a keyboard shortcut, specify the keystrokes for the
shortcut as follows:
• To use the default number of keystrokes, which is one keystroke, skip to step 3.
• To specify multiple keystrokes, or to specify explicitly one keystroke follow these
steps:
2-26
Define Keyboard Shortcuts
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.
View keyboard shortcut conflicts — On the Home tab, in the Environment section,
click Preferences. Select MATLAB > Keyboard > Shortcuts.
The Keyboard Shortcuts preferences pane indicates conflicts using informational and
error icons.
• —An informational icon indicates that two different actions in two different tools
have the same shortcut. For information on resolving these conflicts, see “Actions in
Different Tools Have the Same Shortcut — Evaluating Conflicts” on page 2-28.
• —An error icon indicates that two different actions within the same tool have the
same shortcut. For information on resolving these conflicts, see “Actions in the Same
Tool Have the Same Shortcut — Evaluating Conflicts” on page 2-28.
2-27
2 Desktop
Typically, you want to resolve conflicts indicated by the informational icon when all
the following are true:
Actions in the Same Tool Have the Same Shortcut — Evaluating Conflicts
It can be unnecessary to resolve these conflicts if one or more of the following are true:
For instance, you are performing a two-step procedure. In the first step, you assign
the keyboard shortcut to an action that results in a conflict. Then, in the second step,
you remove the shortcut from the original action.
• 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.
2-28
Define Keyboard Shortcuts
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.
By default, no keyboard shortcut is available for adding a Help topic to the list of
favorites. If you frequently mark topics as favorites, you can define a keyboard shortcut
for this action, as follows:
Notice that the All possible conflicts table is empty, which indicates that no other
desktop action is currently using this combination of keystrokes.
2-29
2 Desktop
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.
Suppose you frequently adjust indenting in the MATLAB Editor. However, you have
difficulty remembering the default keyboard shortcut of Ctrl+[ for decreasing the indent.
So, you decide to change it to something that is easier to remember.
This example changes the keyboard shortcut for Decrease Indent in the MATLAB
Editor from Ctrl+[ to Ctrl+Backspace:.
1 On the Home tab, in the Environment section, click Preferences > Keyboard >
Shortcuts.
2 Under Active settings, choose Windows Default Set.
3 In the filter field, press Ctrl+[.
4 Under Action name, select Decrease Indent.
5 In the table labeled Shortcuts for Decrease Indent, under Shortcut, click Ctrl
+[. MATLAB makes the field editable.
2-30
Define Keyboard Shortcuts
The first time you press the key combination, it deletes Ctrl+[. The second time
you press it, Ctrl+Backspace appears in the field.
7 Click Apply.
MATLAB saves your changes to the Windows Default Set (modified) settings.
Suppose you find yourself frequently pressing the wrong keyboard shortcut. For example,
on Windows, you press Alt+Enter (to apply a code analyzer autofix) instead of Ctrl
+Enter (to evaluate the current cell in the MATLAB Editor ). To avoid accidentally
applying an autofix, delete the Alt+Enter shortcut by following these steps:
2-31
2 Desktop
6
Click the remove button .
7 Click Apply.
You cannot delete default keyboard shortcut sets, such as Windows Default Set.
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-31.
2-32
Define Keyboard Shortcuts
• “Tools for Which You Cannot Customize Keyboard Shortcuts” on page 2-33
• “Actions for Which You Cannot Customize Keyboard Shortcuts” on page 2-34
You cannot change the keyboard shortcuts associated with the following tools or portions
of tools:
• Figure windows—For example, you cannot modify the keyboard shortcut, Ctrl+S, for
saving a MATLAB .fig file.
• Toolboxes—For example, you cannot modify keyboard shortcuts in the SimBiology®
desktop.
• Incremental search—You can modify the keyboard shortcuts for initiating a forward
or backward incremental search. However, you cannot change the keyboard shortcuts
that you use within incremental search mode, such as Ctrl+Shift+S to search
forward.
• Dialog boxes—For example, you cannot create a keyboard shortcut for the OK button.
2-33
2 Desktop
The following table describes some frequently used actions for which you cannot
customize keyboard shortcuts.
In the Function Browser, pressing Esc up to three times has the following
effects:
2-34
Define Keyboard Shortcuts
2-35
2 Desktop
To specify page setup options for printing from the Command Window, right-click in the
Command Window, and then select Page Setup.
To specify page setup options for printing from the Editor, first select the Editor tab.
Then, in the File section, click Print and select Page Setup.
1 Click the Layout, Header, or Fonts tab in the dialog box and set those options for
that tool, as detailed in subsequent sections. On Mac platforms, you must first select
MATLAB in the Settings menu in order to see these tabs.
2 Click OK.
3 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-36
Set Print Options
1 From Choose font, select the element, either Body or Header, where Body text is
everything except the Header.
2 Select the font to use for the element.
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.
3 Repeat for the other element.
If you did not select Print header on the Layout pane, you do not need to specify
the Header font.
As an example, for Header text, select Use custom font and then specify the font
characteristics—type, style, and size. After you specify a custom font, the Sample area
shows how the font will look.
2-37
2 Desktop
Tip You can change the font that a desktop tool uses. On the Home tab, in the
Environment section, click Preferences > Fonts > Custom.
2-38
Web Browsers and MATLAB
In this section...
“About Web Browsers and MATLAB” on page 2-39
“Display Pages in Web Browsers” on page 2-41
“Specify Proxy Server Settings for Connecting to the Internet” on page 2-41
“Specify the System Browser for Linux Platforms” on page 2-42
2-39
2 Desktop
The MATLAB Web and Help browsers may not support all the features that a particular
Web site or HTML page uses. For example, the MATLAB Web browser does not display
.bmp (bitmap) image files. Instead use .gif or .jpeg formats for image files in HTML
pages.
2-40
Web Browsers and MATLAB
System Browser
• On Microsoft Windows and Apple Macintosh platforms, MATLAB uses the default
browser for your operating system.
• On UNIX platforms, MATLAB uses the Mozilla Firefox browser. You can specify a
different system browser for MATLAB using Web preferences.
To display a Web page or any file type in the MATLAB Web browser:
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.
2-41
2 Desktop
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.
Note: MATLAB stores the password without encryption in your matlab.prf file.
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.
5 Click OK to accept the changes.
Note: The Mac platform does not have a System Web browser preference.
2-42
Manage Your Licenses
1 On the Home tab, in the Resources section, click Help > Licensing.
2 Select a Licensing option. The following table describes the Licensing options.
Depending on your license type, your system might not include all these options.
Note: Some options require an internet connection. If your internet connection requires
a proxy server, use MATLAB web preferences to specify the server host and port. See
“Specify Proxy Server Settings for Connecting to the Internet” on page 2-41 for more
information.
Option Description
Update Displays a list of all your MathWorks licenses on this computer,
Current with their status. When you select a license and click Update
Licenses Selected License, MATLAB contacts MathWorks to retrieve the
most current version of the License File for the license. The update
process overwrites the current License File on your system. You need
to restart MATLAB.
Activate Starts the activation application, which walks you through the
Software activation process. Answer the questions on each dialog box, select
the license you want to activate, and click Activate.
Deactivate Displays a list of all your MathWorks licenses on this computer,
Software with their status. When you select a license and click Deactivate,
MATLAB deactivates all releases on this computer associated with
the license, and updates the licensing information at the MathWorks
website. You will not be able to use MathWorks software with that
license on this computer.
2-43
2 Desktop
Option Description
scenario, MATLAB returns a deactivation string. To complete
deactivation, save a copy of this string, go to a computer with an
internet connection, and visit the License Center at the MathWorks
website. There you can log in to your MathWorks Account and enter
the deactivation string.
Manage Starts a web browser, opening the My Licenses page associated with
Licenses your MathWorks Account. You can use this page, called the License
Center, to perform many licensing activities.
2-44
Check for Software Updates
Release notes document new features and changes, bug reports, and compatibility
considerations.
6 Decide whether you want to upgrade to the most recent version.
2-45
2 Desktop
Make the following replacements to adjust documented mouse instructions for Macintosh
platforms if you are using a one-button mouse:
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:
1
On the Home tab, in the File section, click
2 In the File Browser dialog box, press Command+Shift+G to open the Go To Folder
dialog box.
3 Enter the full path to the MATLAB folder, for example, /Applications/
MATLAB_R2012a.app.
4 Press Go.
2-46
Macintosh Platform Conventions
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-47
2 Desktop
Preferences
In this section...
“Set Preferences for MATLAB” on page 2-48
“Where MATLAB Stores Preferences” on page 2-49
“Preferences MATLAB Uses When Multiple Releases Are Installed” on page 2-49
“General Preferences” on page 2-51
“Confirmation Dialog Boxes Preferences” on page 2-52
“Source Control Preferences” on page 2-54
“Keyboard Shortcuts Preferences” on page 2-54
“Colors Preferences” on page 2-55
“Colors Programming Tools Preferences” on page 2-56
“Comparison Preferences” on page 2-57
“Toolbars Preferences” on page 2-58
Preferences take effect immediately. They remain persistent across sessions of MATLAB.
Function Alternative
2-48
Preferences
To see the full path for the folder where matlab.prf and related files are located,
type prefdir in the MATLAB Command Window. The name of the preferences folder
matches the name of the release. For instance, for MATLAB R2016b, the name of the
preferences folder is R2016b.
On Mac OS X and iOS, the folder might be in a hidden folder. If so, to access the hidden
folder:
When you change preferences using the MATLAB Desktop, it updates matlab.prf.
When you close MATLAB, it saves those changes to matlab.prf.
Installing MATLAB has no effect on the preferences folder. That is, MATLAB creates,
checks, copies, and writes to the preferences folder when you start up MATLAB, not
when you install it. When you uninstall MATLAB, there is an option in the uninstaller to
remove the preferences folder. However, this option is not selected by default.
When you start up, MATLAB looks for a preferences folder name that matches the
release starting up, and then it does one of the following:
2-49
2 Desktop
• If MATLAB finds a preferences folder name matching the release starting up, then it
uses that folder and the files within it. This is usually the case after the first time you
start MATLAB.
If a preference folder exists but is empty, then MATLAB recreates the default
preference files for the release starting up.
• If MATLAB does not find a preferences folder name matching the release starting up,
then it creates one. Next, MATLAB checks to see if a preference folder exists for any
of the three releases of MATLAB that immediately precede the one you are starting.
• If none of the preference folders from the previous three releases exist, then
MATLAB creates the default preference files for the release starting up.
For example, if you start up R2016a and neither R2015b, R2015a, or R2014b are
installed, then MATLAB creates the default files for the R2016a release. This is
true even if a preference folder exists for the R2014a release or earlier.
• If one or more of the preference folders for the previous three releases exist, then
MATLAB migrates the files from the preferences folder corresponding to the latest
previous release to the preferences folder for the release starting up.
For example, if you start up R2016a and a preference folder exists for both the
R2015b and R2014b releases, then MATLAB migrates the files from the R2015b
preferences folder to the R2016a preferences folder.
This table describes how to control which versions of preferences files MATLAB uses.
To Use: Do This:
Default preference files for a given release • If none of the preference folders for the
of MATLAB three releases immediately preceding
the given release exist, do nothing.
• If one or more of the preference folders
for the previous three releases exist,
make sure that the preferences folder
for the given release exists, but is empty
before starting up.
All the preference files from a release of Ensure that the preferences folder exists
MATLAB up to three releases preceding for that previous release. Delete the entire
the release you plan to start up preferences folder for each release after the
2-50
Preferences
To Use: Do This:
release you want to migrate from, including
the folder for the release of MATLAB you
plan to start up.
The release-specific default for just a Delete just that file from the preferences
particular file in the preferences folder folder for the release of MATLAB you plan
to start up.
General Preferences
You can set preferences for the initial working folder, deleting files, and toolbox path
caching.
On the Home tab, in the Environment section, click Preferences. Select MATLAB
> General. Then, adjust preference options as described in this table.
Preference Usage
Initial working folder Select an option to specify the current folder in
MATLAB when it starts.
2-51
2 Desktop
Preference Usage
Selecting Delete permanently makes the
delete function run faster.
On the Home tab, in the Environment section, click Preferences. Select MATLAB
> General > Confirmation Dialogs. Then, adjust preference options as described in
the table below.
This table summarizes the core MATLAB confirmation dialog boxes. There might be
additional confirmation dialog boxes for other products you install.
2-52
Preferences
For details, see “Save and Load Workspace Variables” on page 5-15.
2-53
2 Desktop
On the Home tab, in the Environment section, click Preferences. Select MATLAB
> General > Source Control. Then, select an option from the list.
On the Home tab, in the Environment section, click Preferences. Select MATLAB
> Keyboard > Shortcuts. Then, adjust preference options as described in the table
below.
Preference Usage
Active settings Select or import a set of predefined
keyboard shortcuts.
2-54
Preferences
Preference Usage
• Compare active settings to another set.
Colors Preferences
You can specify the text and background color for desktop tools, as well as colors for
highlighting syntax elements of MATLAB code.
2-55
2 Desktop
On the Home tab, in the Environment section, click Preferences. Select MATLAB
> Colors. Then, set options as described in the table below.
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.
On the Home tab, in the Environment section, click Preferences. Select MATLAB
> Colors > Programming Tools. Then, set options as described in the table below.
Preference Usage
Code analyzer colors • Warnings—Specifies the color Code Analyzer uses to identify
code in the Editor for which there are warning messages.
2-56
Preferences
Preference Usage
• Autofix highlight—Specifies the color Code Analyzer uses to
identify code in the Editor for which there is an automatic fix.
Comparison Preferences
Colors
You can change and save your diff color preferences for the Comparison tool. You can
apply your color preferences to all comparison types.
On the Home tab, in the Environment section, click Preferences. Select MATLAB
> Comparison. Then, set options as described in the table below.
Preference Usage
Colors Set colors to help you quickly identify differences,
modifications, and merges in comparison reports. Choose
colors from the drop-down menus. View the colors in
the Sample pane. To use your modified settings in
comparisons, click Apply. Refresh any open comparison
reports to use the new colors.
2-57
2 Desktop
Preference Usage
Active Settings To save your modified color preferences for use in future
MATLAB sessions, click Save As. Enter a name for your
color settings profile and click OK.
Use the check box to control external source control interactions: Allow external
source control tools to use open MATLAB sessions for diffs and merges. After
you configure your source control tool to use MATLAB Comparison tool, the Comparison
tool prompts you to set this preference. For details, see “Customize External Source
Control to Use MATLAB for Diff and Merge”.
Toolbars Preferences
You can customize some toolbars in the MATLAB application.
On the Home tab, in the Environment section, click Preferences. Select MATLAB
> Toolbars. Then, set options as described in the table below.
For step-by-step instructions on setting these preferences, see “Access Frequently Used
Features” on page 2-9.
Preference Usage
Toolbar Select the toolbar you want to customize.
Layout Rearrange 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.
2-58
Web Preferences
Web Preferences
Web preferences enable you to specify Internet connection information to MATLAB.
Limitations
You can set Web preferences on the Home tab, in the Environment section. Click
Preferences. Select MATLAB > 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.
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.
2-59
2 Desktop
Preference Usage
Test connection Ensure that your settings work.
2-60
3
Entering Commands
MATLAB immediately adds variable a to the workspace and displays the result in the
Command Window.
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.
If you end a statement with a semicolon, MATLAB performs the computation, but
suppresses the display of output in the Command Window.
b = 2;
To enter multiple statements on multiple lines before running any of the statements, use
Shift+Enter between statements. This action is unnecessary when you enter a paired
keyword statement on multiple lines, such as for and end.
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 commands that end with a semicolon
do not. For example, enter the following three statements at the command line:
A = magic(5), B = ones(5) * 4.7; C = A./B
A =
17 24 1 8 15
3-2
Enter Statements in Command Window
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.
To clear a command from the Command Window without executing it, press the Escape
(Esc) 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
1 Click the Browse for functions button, . In the Command Window, this button is
to the left of the prompt. In the Editor, the button is on the Editor tab, in the Edit
section. The Function browser opens.
Tip The Function browser closes when you move the pointer outside of it. To keep the
browser open, drag it by the top edge to a different location.
2 Optionally, select a subset of products to display in the list. Click the product area
at the bottom of the browser (where the text All installed products appears
by default), and then set the Selected Products preference and click OK. This
preference also applies to the Help browser.
3 Find functions by browsing the list or by typing a search term. For example, search
for the term fourier.
3-4
Find Functions to Use
In the search results, a parenthetical term after a function name indicates either
that the function is in a product folder other than MATLAB, or that there are
multiple functions with the same name. For example, fft (comm) corresponds to
the fft function in the Communications System Toolbox™ folder.
4 Select a function that you would like to use or learn more about, as follows.
• Insert the function name into the current window by double-clicking the name.
Alternatively, drag and drop the function name into any tool or application.
• View syntax information for the function by single-clicking its name. A brief
description for each of the syntax options displays in a yellow pop-up window.
3-5
3 Entering Commands
Tip 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.
You can change the font that the Function browser uses by setting preferences. On the
Home tab, in the Environment section, select Preferences > Fonts. By default, the
Function browser uses the desktop text font and the pop-up window uses the Profiler
font.
3-6
Format Output
Format Output
MATLAB displays output in both the Command Window and the Live Editor. You can
format the output display using several provided options.
In this section...
“Format Line Spacing in Output” on page 3-7
“Format Floating-Point Numbers” on page 3-8
“Wrap Lines of Code to Fit Window Width” on page 3-9
“Suppress Output” on page 3-9
“View Output by Page” on page 3-9
“Clear the Command Window” on page 3-10
x =
1.3333 0.0000
• compact — Suppresses the display of blank lines.
>> x = [4/3 1.2345e-6]
x =
1.3333 0.0000
3-7
3 Entering Commands
format compact
Note: Line spacing display options do not apply in the Live Editor.
For example, suppose that you enter x = [4/3 1.2345e-6] in the Command Window.
The MATLAB output display depends on the format you selected. This table shows some
of the available numeric display formats, and their corresponding output.
Note: The text display format affects only how numbers are shown, not how MATLAB
computes, or saves them.
format short
format short e
format long
See the format reference page for a list and description of all supported numeric
formats.
3-8
Format Output
Suppress Output
To suppress code output, add a semicolon (;) to the end of a command. This is useful
when code generates large matrices.
Running the following code creates A, but does not show the resulting matrix in the
Command Window or the Live Editor:
A = magic(100);
Output in the Command Window might exceed the visible portion of the window. You can
view the output, one screen at a time:
3-9
3 Entering Commands
• On the Home tab, in the Code section, select Clear Commands > 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.
See Also
clc | format | home | more
3-10
Stop Execution
Stop Execution
To stop execution of a MATLAB command, 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.
See Also
drawnow | getframe | pause
3-11
3 Entering Commands
To search for specified text in the Command Window, on the Command Window title
bar, click , and then select Find. The Find dialog box opens. The search begins at the
current cursor position. MATLAB finds the text you specified and highlights it.
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.
You can increase the amount of information available in the Command Window so that
more text is available for searching. Doing so requires more memory. On the Home tab,
in the Environment section, click Preferences. Select MATLAB > Command
Window, and then increase the setting for Number of lines in the command window
scroll buffer.
Clearing the command window (for example, with the clc function), empties the scroll
buffer. The cleared text is no longer available for searching. To clear your display in the
Command Window without clearing the buffer, use the home function.
You can also perform an incremental search in the Command Window using keyboard
shortcuts.
3-12
Find Text in Command Window or History
An incremental search field appears in the bottom right corner of the MATLAB
Desktop window. For a forward search, the text F Inc Search appears. The F
indicates a forward search.
2 Begin typing your search term.
When you enter lowercase letters in the incremental search field, MATLAB looks for
both lowercase and uppercase instances of the letters. For example, if you enter b,
MATLAB looks for b and B. However, if you enter uppercase letters, MATLAB only
looks for instances that match the case you entered.
3 Perform incremental search actions using these keyboard shortcuts:
If you search for a set of characters that does not appear in the Command Window
text, Failing appears in the incremental search field.
4 End incremental searching by pressing Esc (escape), Enter, or any other key that is
not a character or number.
The incremental search field disappears. The cursor remains at the position where
the text was last found, with the search text highlighted.
3-13
3 Entering Commands
1 In the Command History window, type in the Search field. To display the Search
field if is not visible, click , and then select Find.
The Command History window searches backward and selects the previous entry
that contains the sequence of letters you typed.
3 Select from the different search options using the buttons to the right of the search
field. Options include (match case), (match anywhere within command), and
(match at beginning of command).
4 Find the previous or next occurrence of the entry with the up and down arrow keys,
respectively.
5 Press Esc to clear the search.
3-14
Create Shortcuts to Rerun Commands
1 On the Home tab, click New, and then select Command Shortcut.
If the Shortcuts tab is on the desktop, you can also click New Shortcut in the
Manage section.
2 Complete the Shortcut Editor dialog box:
You also can drag and drop statements from the Command Window, Command
History Window, or a file.
format compact
clear
workspace
filebrowser
clc
3-15
3 Entering Commands
The shortcut icon and label appear on the quick access toolbar. If the shortcut icon
does not appear on the quick access toolbar, use the drop-down to see the full list.
To organize and edit shortcuts, on the Shortcuts tab, in the Manage section, click
Organize Shortcuts to open the Shortcuts Organizer dialog box. If the Shortcuts
tab is not visible, go to the Home tab, and in the Environment section, click
Layout. Then, under Show, select Shortcuts Tab.
3 Run a shortcut by clicking its icon on the Shortcuts tab.
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-16
Set Command Window Preferences
On the Home tab, in the Environment section, click Preferences. Select MATLAB
> Command Window, and then adjust preference options as described in the table
below.
Preference Usage
Text display Select a Numeric format option to specify the output format of
numeric values in the Command Window.
For details, see “Wrap Lines of Code to Fit Window Width” on page
3-9.
Select Set matrix display width to eighty columns to limit the
width of matrix output.
3-17
3 Entering Commands
Preference Usage
Note: If you also select Wrap lines, and the width of the Command
Window is fewer than 80 characters, each row of 80 characters of
matrix output wraps to fit within the width of the Command Window.
Select Show getting started message bar to display the Command
Window message bar that provides links to introductory information.
The scroll buffer size does not impact the number of lines you can
recall. By default, you can use the up arrow key ↑ to recall all lines
shown in the Command History window, regardless of how many
lines you can see in the Command Window.
Tab key Tab size specifies the number of spaces assigned to the tab key.
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-18
Set Keyboard Preferences
To set Keyboard Preferences, on the Home tab, in the Environment section, click
Preferences. Select MATLAB > Keyboard, and then adjust preference options as
described in this table.
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.
3-19
3 Entering Commands
Preference Usage
3-20
Set Keyboard Preferences
Preference Usage
Select one of these Show mismatch with options to specify how
MATLAB indicates mismatched delimiters
3-21
3 Entering Commands
In this section...
“Syntax Highlighting” on page 3-22
“Delimiter Matching” on page 3-23
“Tab Completion” on page 3-23
“Function Syntax Hints” on page 3-26
Syntax Highlighting
To help you identify MATLAB elements, some entries appear in different colors in the
Command Window and the Editor. 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.
You can change syntax highlighting preferences. On the Home tab, in the Environment
section, click Preferences. Select MATLAB > Editor/Debugger > Languages.
Preference changes do not apply in live scripts.
3-22
Check Syntax as You Type
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.
By default, MATLAB indicates matched and mismatched delimiters and paired language
keywords as follows:
If a matching delimiter exists, but it is not visible on the screen, a pop-up window
appears and shows the line containing the matching delimiter. Click in the pop-up
window to go to that line.
The pop-up window for delimiter matching is not supported in live scripts.
You can change delimiter matching indicators, and when and if they appear. On the
Home tab, in the Environment section, click Preferences. Select MATLAB >
Keyboard. Preference changes do not apply in live scripts.
Tab Completion
MATLAB can help you avoid typographical errors by completing the names of functions,
models, MATLAB objects, files, folders, variables, structures, graphics properties,
parameters, and options.
3-23
3 Entering Commands
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.
• Search a long list before making a selection, by adding additional characters to your
original term.
• Complete parts of a name that use dot notation by adding a dot, and then pressing the
Tab key.
• Complete the names and values of graphics properties. Begin typing the first part of a
property, and then press the Tab key. Type a comma after each property.
• Complete parameter names and options for certain functions. When entering a
command, at the location of a parameter or option, type ', and then press the Tab
key. Completion of parameters and options is not available for all functions.
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.
Not supported in live scripts.
• Names of variables defined in the active document. The variable must be valid at the
current location of the cursor (that is, already defined).
• Names of class properties and methods in class definition files. Not supported in live
scripts.
In the Editor, MATLAB does not complete field names of structure arrays defined only
within the active file.
3-24
Check Syntax as You Type
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.
Tab completion is enabled by default. To change this setting, on the Home tab, in the
Environment section, click Preferences. Select MATLAB > Keyboard. Preference
changes do not apply in live scripts.
This example shows how to complete the name for the containers.Map.keys method.
1 In the Command Window, type help cont, and then press Tab.
3-25
3 Entering Commands
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.
To use function syntax hints, type a function name with an opening parenthesis, and
then pause. A tooltip opens showing the basic syntax for the function.
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.
3-26
Check Syntax as You Type
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, click Preferences. Select MATLAB > Keyboard, and then
set the options for Function hints. Preference changes do not apply in live scripts.
3-27
3 Entering Commands
Command History
In this section...
“What Is the Command History?” on page 3-28
“Use Command History Commands” on page 3-29
“Change the Command History Date Format” on page 3-30
“Command History Preferences” on page 3-30
To view the command history, press the up-arrow key, ↑, in the Command Window. To
retrieve a command using a partial match, type any part of the command at the prompt,
and then press the up-arrow key.
To dock or detach the Command History window, click , and then select an option. To
view the Command History if it is closed: on the Home tab, in the Environment section,
click Layout. Then, under Show, click Command History and select either Docked or
Popup.
MATLAB saves statements that run in the Command Window to the history file,
History.xml. These statements include those 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 Variables editor are not included in the Command History.
All entries remain until you delete them, or until the number of commands in the history
file exceeds the number of commands to save, as specified in the Command History
preferences. When the specified limit is reached, MATLAB automatically deletes the
oldest entries. By default, the Command History saves 25,000 commands.
3-28
Command History
• Press the up arrow key (↑) until the command you want appears at
the prompt, and then press Enter
• Double-click an entry or entries in the Command History window,
or select an entry and press Enter.
3-29
3 Entering Commands
1 Change the short date format for your operating system as described in its
documentation.
2 Restart MATLAB.
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.
You can also change the way you search for previously executed statements in the
command history. Select from different search text matching options and change the way
results are displayed in the Command History window.
To set Command History preferences, on the Home tab, in the Environment section,
click Preferences. Select MATLAB > Command History, and then adjust the
preference options as described in this table:
Option Usage
Save Select Save exit/quit commands to save exit and quit
commands in the command history.
Select Save consecutive duplicate commands to
save consecutive executions of the same statement in the
command history.
3-30
Command History
Option Usage
• With this option selected, if you run magic(5) two times
in a row, the entries for magic(5) appear on separate
lines in the command history.
• With this option cleared, the command history retains
only one entry for magic(5) and displays a tally of
consecutive executions to the left.
Select Don't save history file to prevent saving the
command history across sessions. This option is useful when
multiple users share the same machine. For example, the
option prevents each user from viewing statements others
have run.
3-31
3 Entering Commands
Option Usage
Select Show execution time to display an approximate
execution time to the right of each statement. Times display
for any statements that takes longer than 0.1 seconds to
execute.
3-32
4
See Also
doc
More About
• “MATLAB Code Examples” on page 4-3
4-2
MATLAB Code Examples
Standalone Examples
A standalone example is a readable version of a MATLAB script that shows how to
accomplish a particular task. MATLAB and all MATLAB toolboxes include examples as
part of the installed documentation. (Before release R2012b, these examples were called
demos.)
Access examples by clicking Examples on the right or bottom left of the main
documentation page for a particular product. You can also access examples by clicking
4-3
4 Help and Product Information
MATLAB include various examples that demonstrate various functionality. For instance,
click on Graphics to view examples demonstrating plotting functionality in MATLAB.
Each example combines comments, code, and output together in a formatted document.
You can open the corresponding script in the Editor by clicking Open Script or Open
Live Script to the right of the example name, or by clicking Open Script or Open Live
Script at the top of the example page in the Help browser.
4-4
MATLAB Code Examples
• Run one section at a time and view the incremental results. Select the first section,
and then step through the script by clicking Run and Advance, .
•
Run the entire script by clicking Run or Run All .
Inline Examples
The product documentation also includes inline code excerpts, such as examples on
function pages like cos or plot. You can run inline code from the Help browser by
selecting the code, right-clicking, and then selecting Evaluate Selection, as shown.
(On Macintosh systems, press Shift+F7, which copies code to the Command Window for
evaluation.)
4-5
4 Help and Product Information
See Also
demo | echodemo
Related Examples
• “Run Code Sections”
External Websites
• File Exchange
4-6
Search Syntax and Tips
When you view pages linked from the search results, search terms appear with
highlights. To clear the highlights, press the Esc key.
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.
Example: "plot tools" finds pages that contain plot tools, in that sequence,
with no words between them.
* Wildcard
Requires at least two nonwildcard characters, and cannot appear at the start of
a keyword or in an exact phrase.
Example: "plot tools" NOT "time series" finds pages with plot tools but
excludes pages with time series.
4-7
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.
You can filter search results using facets that appear on the left side of the page. For
example, view MATLAB topics by selecting MATLAB and Help Topics.
4-8
Search Syntax and Tips
4-9
4 Help and Product Information
In this section...
“Bookmark Favorite Pages” on page 4-10
“View Page Locations” on page 4-11
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-10
Bookmark and Share Page Locations
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 website.
This documentation is available to anyone, even if they do not have MathWorks
products. However, to access archived documentation from previous releases, as well
as Korean and Chinese documentation, 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 website.
4-11
4 Help and Product Information
4-12
Contact Technical Support
External Websites
• How do I access the MathWorks FTP site?
• MathWorks Support Page
4-13
4 Help and Product Information
Help Preferences
To set Help preferences:
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.
4-14
Help Preferences
Preference Usage
Links to reference pages from the Current Folder browser always
open in the Help browser.
Language (selected non- Specify whether you want documentation in the Help browser
English systems only) and context-sensitive help to appear in English. Installed non-
English documentation is not always current.
To adjust the font size in the Help browser or MATLAB Web browser, use the Ctrl +
Mouse Scroll keyboard shortcut.
More About
• “Japanese Documentation” on page 4-16
• “Korean and Chinese Documentation” on page 4-17
4-15
4 Help and Product Information
Japanese Documentation
Many MathWorks products provide versions of the documentation translated from
English to Japanese.
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, access the Environment section on the Home tab, and click
Preferences. Select MATLAB > Help, and set the Help Language preference to
English.
The Language preference is available when the system locale is Japanese and the
translated documentation is installed. The preference changes the language only in
the Help browser and context-sensitive help. If the documentation for a product is not
translated, the Help browser displays the English documentation.
When the translated documentation is available, you can view it by setting your Help
Documentation Location preference to view documentation on the web. Alternatively,
download it from the MathWorks website at http://www.mathworks.co.jp/help.
For information about documentation in other languages, contact your MathWorks sales
and service office.
Related Examples
• “Set Locale on Windows Platforms” on page 9-5
• “Set Locale on Linux Platforms” on page 9-8
• “Set Locale on Mac Platforms” on page 9-7
4-16
Korean and Chinese Documentation
1 From the Home tab, in the Environment section, click the Preferences button.
2 From the left pane, select Help.
3 For Documentation Location, select Web, on mathworks.com (Internet
connection required). Then for Language, select either your default language
(Korean or Chinese) or English, and click OK.
4 Open the documentation from the Home tab Resources section by clicking the
Help button.
If the documentation does not display in the language you want, the subset of
documentation you are viewing might not be translated.
4-17
4 Help and Product Information
4-18
5
• On the Home tab, in the Environment section, click Layout. Then, under Show,
select Workspace.
• Type workspace in the Command Window.
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 “Base and
Function Workspaces”.
To display additional columns such as size and range, on the Workspace browser title
bar, click , and then click Choose Columns.
To select which columns to display, right-click the Workspace browser title bar and select
or clear the desired column names.
You can also use the who command in the Command Window to view a list of variables.
To list information about size and class, use the whos command.
Create Variables
You can create new variables in the workspace by running MATLAB code or using
existing variables.
To create a new variable, enter the variable name in the Command Window, followed by
an equal sign (=) and the value you want to assign to the variable. For example, if you
run these statements, MATLAB adds the three variables x, A, and I to the workspace:
x = 5.71;
5-2
Create and Edit Variables
A = [1 2 3; 4 5 6; 7 8 9];
I = besseli(x,A);
If you do not end the assignment statement with a semicolon (;), MATLAB displays the
result in the Command Window. For example,
x = 5.71
x =
5.7100
If you do not explicitly assign the output of a statement to a variable, MATLAB generally
assigns the result to the reserved word ans. The value of ans changes with every
statement that returns an output value that is not assigned to a variable. For example,
sin(1)
ans =
0.8415
To create a new workspace variable from an existing variable, in the Variables editor,
select an element, data range, row, or column in an array, and then in the Variable tab,
select New from Selection.
5-3
5 Workspace Browser and Variable Editor
Some variables open a viewer or other tool appropriate for the type of value they have,
such as timeseries. For details, see the documentation for that data or object type.
A or icon next to a variable property in the Variables editor indicates that the
property is protected or private.
Note: The maximum number of elements in a variable that you can open in the
Variables editor depends on your operating system and the amount of physical
memory installed on your system.
To change how the Variables editor displays variables, go to the View tab, and in the
Format section, select a number display format. The display format does not affect
how values are displayed in the Command Window or Workspace browser, or how the
variables are saved.
To edit other variables, open them in the Variables editor. For example, suppose that you
create a cell array, C, by running these commands in the Command Window:
A = magic(4);
C = {A A A};
In the Workspace browser, double-click the variable name C to open it in the Variables
editor.
5-4
Create and Edit Variables
To edit an element of a variable, double-click the element. The element opens in a new
document within the Variables editor. For example, if you double-click element C{1,1}
in the Variables editor, the contents of that cell open in a new tab. You can edit the value
of a variable element by clicking the element and typing a new value. Press Enter or
click another element to save the change.
5-5
5 Workspace Browser and Variable Editor
To return to the parent cell array or structure of an element, go to the View tab and click
the Go Up button.
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 Workspace browser and
Variables editor.
Note:
To modify the size, shape and order of variable elements in the Variable editor, use the
following procedures:
5-6
Create and Edit Variables
Action Procedure
Delete row, column, or variable Right-click the desired row header, column header, or
elements selected elements and select Delete Row or Delete
Column.
Insert new row or column Right-click the desired row header, column header,
or element and select Insert Row Above, Insert
Row Below, Insert Column to the Left, or Insert
Column to the Right. You can also add rows or
columns simply by entering a value in an empty row
or column. For example, to add a row and column to
the array in C{1,1}, enter a value in element (5,5).
Cut variable elements Right-click the desired row header, column header,
or selected elements and select Cut. The cut values
move to the clipboard and are replaced by the default
value for empty elements. For more information, see
“Empty Elements” on page 5-7.
Copy variable elements Right-click the desired row header, column header, or
selected elements and select Copy.
Paste variable elements Right-click the row header, column header, or
element where you want the insertion to begin and
select Paste.
Paste cells from Microsoft Excel Right-click the element where you want the insertion
spreadsheet to begin, and then select Paste Excel Data.
Empty Elements
Empty elements in variables are assigned default values. Default assignments are:
Tables (including timetables) and structure arrays support additional editing actions.
5-7
5 Workspace Browser and Variable Editor
5-8
Create and Edit Variables
5-9
5 Workspace Browser and Variable Editor
Note: The contents of a table are only visible and modifiable when the number of
variables is fewer than 5000. When the number of variables equals or exceeds 5000, you
can only view the table properties.
Changes made to certain variable types in the Variables editor also appear in the
Command Window. For example, suppose you have a table T that contains three
columns, A, B, and C. If you delete column A in the Variables editor, the line T(:,'A')
= []; displays in the Command Window. To suppress code display in the Command
Window, on the View tab, clear the Show MATLAB Code check box.
5-10
Create and Edit Variables
Action Procedure
Copy variable to and from Select the variables, right-click, and then select
clipboard Copy. Then, you can paste the names, for example,
into the Command Window or an external
application. Multiple variables are comma-separated.
5-11
5 Workspace Browser and Variable Editor
Action Procedure
Duplicate variable Select the variables, right-click, and then select
Duplicate. MATLAB creates a copy of the selected
variables.
Rename a workspace variable Right-click the variable name, and then select
Rename. Type the new variable name and press
Enter.
Delete all variables in workspace On the Home tab, in the Variable section, click
Clear Workspace.
You can change the character that delimits decimals in the data when you cut and paste
values from the Variables editor into text files or other applications. 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-22.
Delete Variables
You can delete variables within the Workspace browser.
Action Procedure
Delete all variables in workspace On the Home tab, in the Variable section, click
Clear Workspace.
5-12
Create and Edit Variables
Action Procedure
You can also use the clear function in the Command
Window.
Delete selected variables from Use the clear function in the Command Window.
workspace For example, to clear variables A and B, use the
command clear A B.
To display statistics, on the Workspace browser title bar, click , and then select
Choose Columns. Select the statistics you want MATLAB to calculate.
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:
On the Workspace browser title bar, click , and then select Choose Columns.
Clear the statistics you do not want MATLAB to calculate.
• Exclude large arrays from statistical calculations.
5-13
5 Workspace Browser and Variable Editor
If your data includes NaNs (Not-a-Number values), you can specify that the Workspace
browser statistical calculations consider or ignore the NaNs. On the Home tab, in the
Environment section, click Preferences. Select MATLAB > Workspace, and then
select one of the following:
If a variable includes a NaN, and you select this option, the values for Min, Max,
Var, and several other statistics appear as NaN. However, Mode and several other
statistics show a numeric result.
• Ignore NaNs whenever possible
If a variable includes a NaN, and you select this option, numeric results appear for
most statistics including Min, Max, and Mode. However, Var still appears as NaN.
More About
• “Workspace and Variable Preferences” on page 5-20
• “Save and Load Workspace Variables” on page 5-15
5-14
Save and Load Workspace Variables
You can save any or all the variables in the current workspace to a MAT-file (.mat). You
can load MAT-files later during the current MATLAB session, or during another session,
if you want to reuse the workspace variables.
Action Procedure
Save all workspace variables to a MAT- On the Home tab, in the Variable section,
file click Save Workspace.
save('june10')
Save selected variables to a MAT-file Do one of the following:
save('june10','A','B')
Save part of a variable Use the matfile function. For an example, see
“Save Parts of Variables to MAT-Files”.
Load a MAT-file Select the MAT-file in the Current Folder
browser, right-click, and then select Load.
5-15
5 Workspace Browser and Variable Editor
Action Procedure
You can also use the load function. For
example, load all variables from the file
durer.mat
load('durer')
Load selected variables from a MAT-file Do one of the following:
load('durer','X','map')
Load part of a variable Use the matfile function. For an example, see
“Load Parts of Variables from MAT-Files”.
Action Procedure
Save all workspace variables to a MAT- Use the save function. For example, save
file all current workspace variables to the file
june10.mat
save('june10')
Save selected variables to a MAT-file Use the save function. For example, save only
variables A and B to the file june10.mat
save('june10','A','B')
Save part of a variable Use the matfile function. For an example, see
“Save Parts of Variables to MAT-Files”.
Load a MAT-file Double-click the MAT-file in the Current
Folder browser
5-16
Save and Load Workspace Variables
Action Procedure
You can also use the load function. For
example, load all variables from the file
durer.mat
load('durer')
Load selected variables from a MAT-file On the Home tab, in the Variable section,
click Import Data. Select the MAT-file you
want to load and click Open.
load('durer','X','map')
Load part of a variable Use the matfile function. For an example, see
“Load Parts of Variables from MAT-Files”.
Caution When you load data into the MATLAB workspace, the new variables you create
overwrite any existing variables in the workspace that have the same name.
To see the variables in a MAT-file before loading the file into your workspace, use the
command whos -file filename. This function returns the name, dimensions, size, and
class of all variables in the specified MAT-file.
For example, you can view the contents of the example file durer.mat.
5-17
5 Workspace Browser and Variable Editor
The byte counts represent the number of bytes that the data occupies in memory when
loaded into the MATLAB workspace. Because of compression, data encoding, and
metadata, the space occupied in the file by a variable may be different from the in-
memory size. MATLAB compresses data in Version 7 or higher MAT-files. For more
information, see “MAT-File Versions”.
• To save all workspace variables, on the Home tab, click Save Workspace.
• To save selected workspace variables, select the variables in the Workspace browser,
right-click, and then select Save As.
Then, in the Save As window, specify a file name. In the Save as type menu, select
MATLAB Script.
Variables that cannot be saved to a script are saved to a MAT-file with the same name as
that of the script.
To load the saved variables into the workspace, simply run the script.
Save the entire structure to newstruct.mat. The file contains the variable S.
save newstruct.mat S
whos -file newstruct.mat
5-18
Save and Load Workspace Variables
Save the fields individually. The file contains variables a, b, and c, but not S.
Save only selected fields, such as a and c. The file contains variables a and c, but not b
or S.
More About
• “Load Parts of Variables from MAT-Files”
• “Save Parts of Variables to MAT-Files”
• “MAT-File Versions”
5-19
5 Workspace Browser and Variable Editor
Workspace Preferences
Workspace preferences enable you to configure options for saving workspace variables to
MATLAB scripts. They also enable you to restrict the size of arrays on which MATLAB
performs calculations, and to specify if you want those calculations to include or ignore
NaNs.
To open Workspace preferences, on the Home tab, in the Environment section, click
Preferences. Select MATLAB > Workspace.
Preference Usage
Threshold for saving variables to Specify Maximum array size to limit the
MATLAB script number of elements of arrays saved to a
MATLAB script.
5-20
Workspace and Variable Preferences
Preference Usage
File formatting Set the character width at which text in the
MATLAB script is wrapped by specifying
Maximum characters per line.
n element and smaller arrays show Limit the size of arrays for which the
statistics Workspace browser displays statistics
to improve performance when MATLAB
updates the statistical results in the
Workspace browser.
5-21
5 Workspace Browser and Variable Editor
Preference Usage
MATLAB array size limit By default, MATLAB can use up to 100%
of the size of RAM (not including virtual
memory) of your computer to allocate
memory for each MATLAB array. To
change this limit to a smaller percentage,
select the Limit the maximum array
size to a percentage of RAM check
box. Then move the slider to adjust the
percentage of RAM.
Variables Preferences
When working in the Variables editor, Variables preferences enable you to specify array
formatting, cursor movement, and the decimal separator for exporting data using the
system clipboard.
To open Variables preferences, on the Home tab, in the Environment section, click
Preferences. Select MATLAB > Variables.
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.
5-22
Workspace and Variable Preferences
Preference Usage
Editing Specify where the cursor moves to after you type an
element and press Enter.
More About
• “Create and Edit Variables” on page 5-2
5-23
6
1
Click the search button in the current folder toolbar. The address bar becomes a
search field.
2 Type a portion of a file name. The asterisk character (*) is a wildcard. For example,
to show only file names that begin with coll and have a .m extension, type
coll*.m.
3 Press Enter.
MATLAB displays all files within the current folder (including its subfolders) that
match that file name. If you typed the full path to a folder, that folder becomes the
current folder.
4 Clear the results and show all items in the current folder by pressing the Esc key.
Tip To open the Current Folder browser if it is not open, do the following: on the Home
tab, in the Environment section, click Layout. Then, under Show, select Current
Folder. Show and hide columns, or sort and group columns by clicking , and then
selecting an option.
6-2
Find Files and Folders
To conduct an advanced search for files, open the Find Files tool. On the Home tab, in
the File section, click Find Files. Enter your search criteria in the dialog box that opens.
Use the Look in menu to specify the folders you want to search. Select Entire MATLAB
Path to search all folders on the MATLAB search path. Alternatively, you can enter the
full path for one or more folders. Separate each path with a semicolon (;).
Click Find to begin the search. Search results appear 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. To see file locations, select Show full path names.
Open one or more files by right-clicking the files and selecting one of the Open options.
You can search for files with only a specified extension, by selecting an option in the
Include only file type(s) menu. For example, select *.m, *.mlx to limit the search to
MATLAB program files.
6-3
6 Managing Files in MATLAB
1 In the Include only file type(s) menu, select All files (*).
2 Under More options, select the Skip file type(s) box and click Edit. The Edit
Skipped File Extensions dialog box opens.
3 Select the State check box for the file types to exclude from your search.
4 Click OK to accept your changes.
You can remove any file extension from the list by selecting the extension to highlight it.
Then, click Remove.
Under More options, you can choose to search file contents for a partial word. From
the Search type menu, select Contains text. To find an exact full-word match, select
Matches whole word.
Searching within large files can be time consuming. To speed up your search, specify a
file size in the Skip files over field. The Find Files tool ignores files larger than the size
you specify.
Troubleshooting
If the Find Files tool does not find the file you want, try the following:
• When searching for file names, use the asterisk character (*) as a wildcard character
to expand your search. For example, to show file names that begin with coll and
have a .m extension, type coll*.m.
• Select the Include Subfolders check box if the file might be in a subfolder.
• If you select the Skip file type(s) check box, ensure that you do not exclude relevant
file types from your search. Click Edit and review the Edit Skipped File Extensions
dialog box. Ensure that relevant file types do not have the State check box selected.
See Also
dir | exist | what | which
More About
• “Find Functions to Use” on page 3-4
6-4
Find Files and Folders
6-5
6 Managing Files in MATLAB
You can compare files and folders using any of these methods:
• Select a file or folder, right-click and select Compare Against, and browse to
select a second item to compare.
• For two files or subfolders in the same folder, select the files or folders, right-click
and select Compare Selected Files/Folders.
• If you have a file open in the Editor, on the Editor or Live Editor tab, in the File
section,
6-6
Comparing Files and Folders
If you specify two files or folders to compare using either the Current Folder browser
or the visdiff function, then the Comparison tool automatically performs the default
comparison type.
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 using the Comparison tool. See
“Select Files or Folders to Compare from the Comparison Tool” on page 6-21.
Comparison report features depend on your comparison type. You can use the tool to:
6-7
6 Managing Files in MATLAB
• Compare and merge lines in two text files (some other applications refer to this as a
file diff operation). See “Comparing Text and Live Scripts” on page 6-11.
• Compare and merge variables in two MAT-files. See “Comparing MAT-Files” on page
6-17.
• Determine whether the contents of two binary files match. See “Comparing Binary
Files” on page 6-20.
• Compare any combination of folders, zip files, or Simulink manifests to determine:
• 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 to compare XML files generated from them. For information, see “Model
Comparison”.
To select items to compare, see “Select the Files or Folders to Compare” on page 6-6.
You can perform file list comparisons for any combinations of folders, zip files, and
Simulink Manifests.
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:
6-8
Comparing Files and Folders
• Determine if files with identical names that are common to both comparison lists also
have identical content.
• Open a new comparison of two files or folders that are common to both comparison
lists, but have different content.
• Open a file for viewing in the Editor.
• Specify filters to ignore certain files or folders
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.
To define filters to exclude unimportant differences, on the View tab, click the Filter
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:
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 Difference Summary column.
6-9
6 Managing Files in MATLAB
The following image shows an example of the Comparison tool when two folders are
compared. The results are sorted by Type.
6-10
Comparing Files and Folders
• 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.
• 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-21.
To select files to compare, see “Select the Files or Folders to Compare” on page 6-6.
6-11
6 Managing Files in MATLAB
visdiff(fullfile(matlabroot,'help','techdoc','matlab_env',...
'examples','lengthofline.m'), fullfile(matlabroot,'help',...
'techdoc','matlab_env','examples','lengthofline2.m'))
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.
Note: When you compare live scripts, the Comparison tool converts all formatted content
to publish markup. This generates the same code as when you save a live script as a
MATLAB Code file (.m). The files are then compared as text. The tool does not compare
stored output.
The Comparison tool report displays the files side by side and highlights lines that do not
match, as follows:
6-12
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 24) in green. Also, notice that the tool
6-13
6 Managing Files in MATLAB
takes the additional line into 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,
Because text files can be lengthy, the Comparison tool provides toolstrip buttons to help
you step through the results from one difference to the next.
• Click the right arrow button to go to the next set of lines that differ.
If no additional sets of lines differ, the right arrow takes you to the end of the file.
• Click the left arrow button to go to a previous set of lines that differ.
If no previous set of lines differ, the left arrow takes you to the beginning of the file.
Merge Differences
When comparing text files you can merge changes from one file to the other. Merging
changes can be useful when resolving conflicts between different versions of files.
Merging is not available when comparing live scripts.
Tip You can only merge from left to right. If you want to merge into the other file, use
Swap Sides before you start merging. Swap Sides reverts any merges already made
and creates a new comparison report for the original files.
6-14
Comparing Files and Folders
1 Select a difference in the report and click the Merge button to copy the selected
difference from the left file to the right file.
Merged differences display gray row highlighting, and a green merge arrow.
The merged file name at the top of the report displays the dirty flag (filename.m*)
to show you that the file contains unsaved changes.
2 To revert the last merge operation, click Undo in the Merge section. You can click
Undo repeatedly, or Redo to reapply a merge.
Tip You can click Swap Sides to start again and revert all merges.
3 To save your changes, click Save Merged File. To save to a different name, select
Save Merged File > Save Merged File As.
4 If you want to inspect the files in the Editor, click the line number links in the
report.
Tip Save your merge changes from the comparison report before making any changes
in the Editor, otherwise the comparison report can become incorrect. The report does
not update to reflect changes you make in the Editor.
To see a summary of differences between two text files, scroll to the bottom of the
Comparison tool and view the list, which contains information such as:
You may want to hide white-space differences to help you distinguish between functional
changes and changes to indentation.
On the View tab, click the Filter button, and check or uncheck the Ignore White
Space item to toggle the display of differences only involving white-space characters.
You can specify whether to show only differences or entire files. It can be useful to hide
unmodified lines in large text comparison reports. When you are showing differences
only and sections are hidden, the report displays messages like the following: 10
unmodified lines hidden.
On the View tab, click the Filter button, and check or uncheck the Show Differences
Only item to toggle the display of sections of the report that do not contain any
differences.
You can increase or decrease the line lengths of the text files in the comparison display.
On the View tab, in the Display section, edit the number in the Column Width edit
box. Resize the window, if necessary.
For details on other comparison tool features, see “Using Comparison Tool Features” on
page 6-21.
On the Comparison tab, in the Comparison section, click Save As > Save as HTML
to save a copy of the comparison report as an HTML file.
1 Open one of the text files you want to compare in the Editor.
To open the example file provided, lengthofline.m, run the following command in
the Command Window:
6-16
Comparing Files and Folders
open(fullfile(matlabroot,'help','techdoc','matlab_env',...
'examples','lengthofline.m'))
2 On the Editor or Live 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. For
example, select the example file lengthofline2.m from the folder where you found
lengthofline.m.
• To compare the open file to the Editor's automatic copy (filename.asv), under
Compare, select Save and Compare with Autosave. If your file is modified,
the Editor saves the file before comparing. For more information, see “Backing
Up Files”.
• To compare an open file that has been changed, but not saved, to the saved
version, under Compare, select Compare with Version on Disk.
Comparing MAT-Files
Note: To select files to compare, see “Select the Files or Folders to Compare” on page
6-6.
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.
6-17
6 Managing Files in MATLAB
• Save a copy of the report as an HTML file. Click Save As > Save as HTML on the
toolstrip.
The report displays a message if the variables in both files are equivalent, but the files
are not identical. Possible causes of the differences between the files include: file formats,
file timestamps, the order in which the variables are stored, or variables contain ignored
differences.
In the Merge column, click the Merge button 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-18
Comparing Files and Folders
6-19
6 Managing Files in MATLAB
If values of the variable differ between the two files, you can click the compare link to
investigate. A new variable comparison report opens. See “Comparing Variables” on page
6-20.
visdiff(fullfile(matlabroot,'toolbox','matlab','demos','gatlin.mat'), ...
fullfile(matlabroot,'toolbox','matlab','demos','gatlin2.mat'))
Comparing Variables
The variable comparison report displays differences in individual array elements or
differing fields of a structure. Double-click pink rows or cells to investigate further layers
of differences, as shown in the following example.
Note: If you are comparing SLX files, and do not have Simulink Report Generator, you
see a binary comparison. For information on SLX comparison reports instead, see “Model
Comparison”.
6-20
Comparing Files and Folders
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.
To view an example binary comparison, compare two example text files and specify
comparison type as binary:
visdiff(fullfile(matlabroot,'help','techdoc','matlab_env',...
'examples','lengthofline.m'), fullfile(matlabroot,'help',...
'techdoc','matlab_env','examples','lengthofline2.m'), 'binary')
• “Select Files or Folders to Compare from the Comparison Tool” on page 6-21
• “Exchange the Left and Right Sides of the Report” on page 6-22
• “Refresh the Report to Show Updated Files” on page 6-22
• “Find Text” on page 6-23
• “Create New Comparisons” on page 6-23
• “Change Color Preferences” on page 6-23
To compare two files or folders from the Comparison tool, follow these steps:
1 From the MATLAB desktop, on the Home tab, in the File section, click Compare.
Select the files or folders to compare.
If the Comparison tool is already open, compare files or folders by clicking the New
button.
6-21
6 Managing Files in MATLAB
You also can drag and drop a file or folder from Windows Explorer to the first and
second 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.
To move the file or folder on the left side to the right side and vice versa, on the
Comparison tab, in the Comparison section, click the Swap Sides button.
After making changes to and saving the files in the Editor, to update the results in
the Comparison tool, on the Comparison tab, in the Comparison section, click the
Refresh button.
6-22
Comparing Files and Folders
Find Text
To find a phrase in the current display, on the Comparison tab, in the Navigate
section, click the Find 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-12.
The dialog box Select Files or Folders for Comparison appears, with the last comparison
files preselected in the first and second file fields. 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 can change and save your diff color preferences for the Comparison tool. You can
apply your color preferences to all comparison types.
6-23
6 Managing Files in MATLAB
5 To return to the default settings, in the Preferences dialog box, click Reset and click
Apply. Refresh the comparison report.
6 If you want to save your modified color preferences for use in future MATLAB
sessions, click Save As. Enter a name for your color settings profile and click OK.
After saving settings, you can select them in the Active Settings list.
visdiff(fileorfoldername1, fileorfoldername2)
See Also
visdiff
Related Examples
• “Model Comparison”
6-24
Manage Files and Folders
6-25
6 Managing Files in MATLAB
To open the Current Folder browser if it is not visible, do the following: on the Home tab,
in the Environment section, click Layout. Then, under Show, select Current Folder.
Double-clicking a subfolder displays its contents, and makes that folder the current
folder.
See Also
delete | edit | mkdir | movefile | open | recycle | rmdir
6-26
Manage Files and Folders
More About
• “Save and Load Workspace Variables” on page 5-15
• “Run Functions in the Editor”
• “Errors When Updating Folders on Search Path” on page 6-54
6-27
6 Managing Files in MATLAB
More About
• “Associating Files with MATLAB on Windows Platforms” on page 1-4
6-28
Files and Folders that MATLAB Accesses
• Change the current folder to the folder that contains the files. Use the cd function or
browse to a different folder in the current folder toolbar:
• Add the folder that contains the files to the search path. Changes you make to the
search path apply to the current MATLAB session. To reuse the modified search path
in future MATLAB sessions, save your changes.
• Store individual files in the userpath MATLAB folder, which is on the search path. To
determine the location of this folder, run the userpath function.
6-29
6 Managing Files in MATLAB
For files in @ (class) and + (package) folders, make the parent folder accessible. For
details, see “Folders Containing Class Definitions”.
If files call other files that are in multiple folders, determine the location of all the called
files by creating a Dependency Report. See “Dependencies Within a Folder”
When there are name conflicts, MATLAB follows these precedence rules:
The file that MATLAB does not use is called a shadowed file. In some cases, MATLAB
warns you that a shadowed file exists.
To see a list of all toolbox folder names supplied with MathWorks products, run:
dir(fullfile(matlabroot,'toolbox'))
See Also
cd | pwd | userpath
More About
• “What Is the MATLAB Search Path?” on page 6-41
6-30
Files and Folders that MATLAB Accesses
6-31
6 Managing Files in MATLAB
On the Home tab, in the Environment section, click Preferences. Then, select
MATLAB > Current Folder.
Preference Usage
History Specify the number of recently used folders maintained in the
Current Folder Toolbar drop-down list.
Refresh Specify how frequently the Current Folder browser updates
to reflect changes to files made from programs and tools other
than MATLAB.
6-32
Current Folder Browser Preferences
Preference Usage
If you do not select the Indicate inaccessible files check box,
then the Current Folder browser displays all files and folders
as undimmed and provides no tooltips.
Toolbar Access the Toolbars preferences to adjust the toolbar layout
and controls for Desktop tools, including the Current Folder
browser.
Initial working Access the General preferences to specify the current folder in
folder MATLAB when it starts.
Hidden Files Specify whether the Current Folder browser displays files
and folders that the operating system hides from system file
browsers and file-listing commands.
To change how dates display in the Current Folder browser, change the short date format
for your operating system. Then, refresh the date display: right-click in the Current
Folder browser and select Refresh. MATLAB uses your operating system's short date
format to display dates in both the Current Folder browser and the Command History.
6-33
6 Managing Files in MATLAB
A path name specifies file locations, for example, C:\work\my_data (on Microsoft
Windows platforms) or /usr/work/my_data (on Linux or Mac platforms). If you do not
specify a path name when accessing a file, MATLAB first searches in the current folder.
To indicate a file in a particular location, specify a path name.
Path name specifications differ, depending on the platform on which you are running
MATLAB. Use the fullfile function to construct path names in statements that work
on any platform. This function is particularly useful when you provide code to someone
using it on a platform other than your own.
fullfile inserts platform-specific file separators where necessary. The file separator
character is the symbol that distinguishes one folder level from another in a path name.
A forward slash (/) is a valid separator on any platform. A backward slash (\) is valid
only on Microsoft Windows platforms. In the full path to a folder, the final slash is
optional. Type filesep in the Command Window to determine the correct file separator
character to use on your platform.
To identify the platform on which MATLAB is currently running, use the ismac, ispc,
and isunix functions.
File names must start with a letter, and can contain letters, digits, or underscores.
Avoid using accent characters such as umlauts or circumflexes in path names. MATLAB
might not recognize the path. In addition, attempts to save a file to such a path might
result in unpredictable behavior.
If a path or file name contains spaces, enclose the input in single quotes. For example:
6-34
Specify File Names
MATLAB always accepts absolute path names (also called full path names), such as I:/
Documents/My_Files. An absolute path name can start with any of the following:
Some MATLAB functions also support relative path names. Unless otherwise noted, the
path name is relative to the current folder. For example:
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 practice 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
A partial path name is the last portion of a full path name for a location on the MATLAB
search path. Some functions accept partial path names.
6-35
6 Managing Files in MATLAB
Be sure to specify enough of the path name to make the partial path name unique.
The maximum length allowed for a path name depends on your platform.
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.
You call function files by specifying the file name without the file extension. MATLAB
returns an error if it cannot find a case-sensitive match on the search path. By default,
MATLAB suggests a function with the correct case.
When multiple files have the same name, MATLAB follows precedence rules to
determine which to call. For more information, see “Function Precedence Order”.
6-36
Specify File Names
• When loading or reading from a file, specify the file name using the correct case.
• When saving or writing to a file, MATLAB saves the file in the case you specify. Two
files with the same name, but different cases can exist in the same folder.
Windows platforms — File names are case insensitive. The Windows operating system
considers two files with the same name to be the same file, regardless of case. Therefore,
you cannot have two file names that differ only by case in the same folder.
• When loading or reading from a file, MATLAB accesses the file with the specified
name that is higher on the search path, regardless of case. For example, if you
attempt to load MYFILE and myfile.mat is higher on the search path than
MYFILE.MAT, then MATLAB loads myfile.mat without warning that there is a case
mismatch.
• When saving or writing to a file, if you specify a file name that already exists in the
folder, MATLAB accesses the existing file without warning. For example, if you save
data to a file named myfile using the save function, and MYFILE.mat already exists
in the folder, the data replaces the contents of MYFILE.mat. However, the file name
remains MYFILE.mat.
See Also
filesep | fullfile | ismac | ispc | isunix | which
More About
• “What Is the MATLAB Search Path?” on page 6-41
6-37
6 Managing Files in MATLAB
In this section...
“Create a Zip Archive” on page 6-38
“Add Files to a Zip Archive” on page 6-39
“Extract Files from a Zip Archive” on page 6-39
“Compare Zip Archive to Unzipped Files” on page 6-40
• To create an empty zip file, right-click white space, and then select New File > Zip
File.
• To create a populated zip file from selected files and folders, select the folders and
files you want to archive, right-click, and then select Create Zip File.
Type over the default file name to specify a descriptive name, for example
listmaster_export.zip, as shown here.
6-38
Create and Extract from Zip Archives
You also can create zip archives programmatically using the zip function. For example,
to zip all files with a .m and .mat extension in the current folder to a zip file archive
named backup.zip, call:
zip('backup',{'*.m','*.mat'});
• 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.
1 Expand the zip file archive to view the archive contents, by clicking the associated +
(expand) button. By default, files within a zip file archive appear dimmed to indicate
that they are not on the MATLAB path.
2 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.
6-39
6 Managing Files in MATLAB
To extract all the contents of a zip file, double-click the zip file in the Current Folder
browser. MATLAB creates a folder with the same name as the zip file, and extracts the
entire contents of the zip file into this folder.
To extract the contents of a zip file programmatically, use the unzip function. unzip
also allows you to specify a target folder. For example, to unzip the file, examples.zip,
to a folder named myfolder, call:
unzip('examples.zip','myfolder')
• 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.
See Also
unzip | zip
More About
• “Comparing Files and Folders” on page 6-6
6-40
What Is the MATLAB Search Path?
The order of folders on the search path is important. When files with the same name
appear in multiple folders on the search path, MATLAB uses the one found in the folder
nearest to the top of the search path.
• The MATLAB userpath folder, which is added to the search path at startup, and is
the default location for storing user files
• The folders defined as part of the MATLABPATH environment variable
• The folders provided with MATLAB and other MathWorks products, which are under
matlabroot/toolbox, where matlabroot is the folder displayed when you run
matlabroot in the Command Window
Class, package, and private folders should not be specified explicitly as part of the
search path.
You can explicitly add folders to the search path for the files you run. For more
information about adding files to the search path, see “Change Folders on the Search
Path” on page 6-45.
6-41
6 Managing Files in MATLAB
By default, the userpath folder is also the startup folder when you start MATLAB
by double-clicking either the MATLAB shortcut on Windows systems or the MATLAB
application on Mac systems.
To determine whether a file is on the search path, run which filename. If the file is on
the search path, MATLAB returns the full path to the file.
To determine whether a file or folder is on the search path, use the Current Folder
browser:
1 In the Current Folder browser, right-click any file or folder, and ensure that 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.
A tooltip opens with an explanation. Frequently, the tooltip indicates that the
file or folder is not on the MATLAB path. If a tooltip does not appear, it may be
disabled. To enable it, go the Home tab and in the Environment section, click
Preferences. Then, select MATLAB > Current Folder. Select Show tooltip
explaining why files are inaccessible to display the tooltip.
Run the path command to view all the folders on the MATLAB search path.
6-42
What Is the MATLAB Search Path?
Alternatively, use the Set Path dialog box to view the entire MATLAB search path. On
the Home tab, in the Environment section, click Set Path. The Set Path dialog box
opens, listing all folders on the search path. For more information on using the Set Path
dialog box, see “Change Folders on the Search Path” on page 6-45.
6-43
6 Managing Files in MATLAB
When you change the search path, MATLAB uses it in the current session, but does not
update pathdef.m. To use the modified search path in the current and future sessions,
save the changes using savepath or the Save button in the Set Path dialog box. This
updates pathdef.m.
See Also
userpath
More About
• “Add Folders to the MATLAB Search Path at Startup” on page 6-49
• “Change Folders on the Search Path” on page 6-45
6-44
Change Folders on the Search Path
In this section...
“For Current and Future Sessions” on page 6-45
“For the Current Session Only” on page 6-47
1 On the Home tab, in the Environment section, click Set Path. The Set Path dialog
box appears.
6-45
6 Managing Files in MATLAB
2 Use the Set Path dialog box to modify the search path.
3 Apply or cancel the search path changes:
• 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 Close.
• To undo your changes, click Revert, and then Close.
• To restore the default search path, click Default, and then Close. The default
search path contains only folders provided by MathWorks.
6-46
Change Folders on the Search Path
Note: The MATLAB (userpath) folder automatically moves to the top of the search path
the next time you start MATLAB. For more information about the userpath folder, see
“userpath Folder on the Search Path” on page 6-41
• Use the Set Path dialog box to make changes to the search path, and do not save the
changes.
1 From the Current Folder browser, select, and then right-click the folder or folders
to add or remove.
2 From the context menu, select Add to Path or Remove from Path, and then
select an option:
• Selected Folders
• Selected Folders and Subfolders
• In the Editor, you also can add or remove the folder that contains an Editor document
from the search path. Right-click the document tab, and then select an option to Add
or Remove the folder from the Search Path.
See Also
addpath | rmpath | savepath
6-47
6 Managing Files in MATLAB
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 (that is, save the pathdef.m file) where that version of MATLAB can
access it.
• Include addpath statements in the startup.m file. Use the same startup.m file
with the multiple versions of MATLAB.
Including addpath statements in the startup.m file also allows you to use your files
with MATLAB on different platforms.
See Also
addpath
More About
• “Startup Options in MATLAB Startup File” on page 1-22
6-48
Add Folders to the MATLAB Search Path at Startup
For more information on creating a startup.m file with addpath statements, see
“Startup Options in MATLAB Startup File” on page 1-22.
Windows
To set the environment variable from a command window, run the command set
MATLABPATH=folders, where folders is a semicolon-separated list of folders. For
example, suppose that you want to add two folders, c:\matlab_files\myfolder1 and
c:\matlab_files\myfolder2, to the MATLABPATH environment variable. Run the
command
6-49
6 Managing Files in MATLAB
set MATLABPATH=c:\matlab_files\myfolder1;c:\matlab_files\myfolder2
Once the environment variable is set, you must start MATLAB from the same command
window for the settings to take effect. The environment variable persists only as long as
the command window is open.
To set the MATLABPATH environment variable in UNIX and Mac, in a terminal, run the
command export MATLABPATH=folders, where folders is a colon-separated list of
folders.
For example, suppose that you want to add two folders, /home/j/Documents/MATLAB/
mine and /home/j/Documents/MATLAB/research, to the MATLABPATH environment
variable on a UNIX platform. Run the command
export MATLABPATH=/home/j/Documents/MATLAB/mine:/home/j/Documents/MATLAB/research
Once the environment variable is set, you must start MATLAB from the same shell for
the settings to take effect. The environment variable persists only as long as the shell
remains open.
Note: If you are using a C shell (csh or tcsh), the command for setting the MATLABPATH
environment variable is setenv MATLABPATH folders.
To add the folders for all future MATLAB sessions, set the MATLABPATH environment
variable as part of your shell configuration script.
More About
• “What Is the MATLAB Search Path?” on page 6-41
• “Change Folders on the Search Path” on page 6-45
6-50
Assign userpath as Startup Folder (Macintosh or UNIX)
export MATLAB_USE_USERWORK=1
From that shell, start MATLAB. Next, verify the current folder in MATLAB.
pwd
/Users/smith/Documents/MATLAB
Confirm that this is the same as the folder defined for userpath.
userpath
/Users/smith/Documents/MATLAB;
path
/Users/smith/Documents/MATLAB
/Users/smith/Applications/MATLAB/R2009a/toolbox/matlab/general
/Users/smith/Applications/MATLAB/R2009a/toolbox/matlab/ops
...
6-51
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.
When MATLAB starts, if there is a problem with the search path, a message such as the
following appears:
Warning: MATLAB did not appear to successfully set the search
path...
For problems with the search path, try these recovery 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.
2 Look for and correct problems with the pathdef.m and startup.m files:
a Restore the default search path and save it. See “Change Folders on the Search
Path” on page 6-45. 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.
4 Restore the default search path using functions:
6-52
Path Unsuccessfully Set at Startup
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.
c Restart MATLAB to ensure that the problem does not recur.
a Run
restoredefaultpath; matlabrc
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-53
6 Managing Files in MATLAB
The behavior varies by platform because it depends on the behavior of similar features in
the operating system.
If your task fails and the error message indicates it is because the folder is on the search
path, then do the following:
6-54
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 Backup Files Preferences” on page 7-9
“Editor/Debugger Autoformatting Preferences” on page 7-10
You can customize the visual display and functionality of the Editor and Debugger using
Editor/Debugger preferences.
On the Home tab, in the Environment section, click Preferences. Select Editor/
Debugger, and then adjust preference options as described in the table below.
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
use, such as Emacs or vi. For example, c:/
Applications/Emacs.exe.
Most recently used file list In the Number of entries field, type the
number of files that you want to appear in the
list of recently used files at the bottom of the
File menu.
Opening files in editor Select On restart reopen 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.
Select Automatically open files when
MATLAB reaches a breakpoint to open a
running program file when MATLAB encounters
a breakpoint in that file.
Automatic file changes Select Save changes upon clicking
away from a file if you want the Editor to
automatically save changes to a file in the Editor
when you click away from the Editor. For the
changes to be automatically saved upon clicking
away from the Editor, you must have already
saved the file at least once.
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.
7-3
7 Editor Preferences
On the Home tab, in the Environment section, click Preferences. Select Editor/
Debugger > Display, and then adjust preference options as described in the table
below.
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.)
On the Home tab, in the Environment section, click Preferences. Select Editor/
Debugger > Tab, and then adjust preference options as described in the table below.
7-4
Editor/Debugger Preferences
Option Usage
Tab size Specify the amount of space inserted when you
press the Tab key.
On the Home tab, in the Environment section, click Preferences. Select Editor/
Debugger > Language, and then adjust preference options as described in the table
below.
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.
7-6
Editor/Debugger Preferences
Preference Usage
Comment formatting In the Maximum column width field, enter the
maximum number of characters you want to allow in
MATLAB Language only a line of comments, and then select where you want
counting to begin.
Consider selecting:
7-7
7 Editor Preferences
Preference Usage
Select an option from Function Indenting Format
(MATLAB Language only) to specify how functions
indent in the Editor, as follows:
On the Home tab, in the Environment section, click Preferences. Select Editor/
Debugger > Code Folding, and then adjust preference options as described in the table
below.
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
If you select this option for any construct, but
clear the Enable Code Folding option, the
construct will not have code folding enabled.
Fold Initially Specifies whether the corresponding
Programming Construct displays collapsed
(folded) the first time that you open a MATLAB
file.
On the Home tab, in the Environment section, click Preferences. Select Editor/
Debugger > Backup Files, and then adjust preference options as described in the table
below.
Preference Usage
Automatically create backup files while Select to have MATLAB automatically save a
working in the MATLAB Editor copy of the files you are currently editing.
Save options Save the backup 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.
7-9
7 Editor Preferences
Preference Usage
File name Select the naming convention you want
MATLAB to use for autosave files. For example:
On the Home tab, in the Environment section, click Preferences. Select Editor/
Debugger > Autoformatting, and then adjust preference options as described in the
table below.
Preference Usage
Enable autoformatting in Live Editor Select to enable autoformatting options in the
Live Editor. Once enabled, options can then be
enabled or disabled individually.
Text format Select *italic*, **bold** to enable bold and
italic formatting using asterisks (*).
Select _italic_, __bold__ to enable bold and
italic formatting using underscores (_).
7-10
Editor/Debugger Preferences
Preference Usage
Select `monospace`, |monospace| to enable
monospace autoformatting.
Section break Select %%, ***, or --- for section break to
enable inserting section breaks by entering %%,
***, or --- and then Enter.
Select %% text for section break and
heading to enable inserting section breaks with
headings by entering %%text and the Enter.
Insert Options Select $LaTeX$ for LaTeX equation to enable
converting LaTeX expressions into equations
using the format $LaTeX$.
Select URL for hyperlink to enable converting
internet paths automatically to hyperlinks.
Select <URL> for hyperlink to enable
converting internet paths to hyperlinks using
the format <URL>.
Select [Label](URL) for labeled hyperlink
to enable converting internet paths to labeled
hyperlinks using the format [Label](URL).
Text Style Select #text for title to enable inserting titles
using the format #text.
Select ##text for heading to enable inserting
headings using the format ##text.
Select Automatic bulleted lists (*, +, or -) to
enable creating bulleted lists by entering *, +, or
- followed by a space.
Select Automatic numbered lists (1., 2., etc.)
to enable creating numbered lists by entering
1., 2., and so on, followed by a space.
7-11
7 Editor Preferences
In this section...
“Code Analyzer Preferences” on page 7-12
“Searching Messages in the Code Analyzer Preferences Dialog Box” on page 7-13
On the Home tab, in the Environment section, click Preferences. Select Code
Analyzer, and then adjust preference options as described in the table below.
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.
7-12
Code Analyzer Preferences
Option Usage
You trigger autofix by clicking the Fix button in
a Code Analyzer message.
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-13
7 Editor Preferences
7-14
Code Analyzer Preferences
In a given category Click the down arrow to the right You want to review messages that
of the search field, click Show describe coding practices that make
Messages in Category, and then it difficult for others to use your
click the category you want. code.
7-15
7 Editor Preferences
To display Code Analyzer error messages that contain the word variable and are
disabled:
1 Click the down arrow in the search field, and then select Show All Errors.
The search field now contains severity:error variable enabled:false. Only the
messages that fulfill those requirements appear in the Preferences pane.
To restore the list of all messages, click the clear search button .
7-16
8
Add-Ons
Get Add-Ons
To extend the capabilities of MATLAB and gain additional functionality for specific
tasks and application, use add-ons. You can find and install add-ons using the Add-On
Explorer. To open the Add-On Explorer, go to the Home tab and in the Environment
Find add-ons by browsing through available categories located on the left side of the Add-
On Explorer window, or by using the search bar.
Click an add-on to open its detailed information page. From this page you can:
• View additional information about the add-on, such as included files and available
documentation.
• Install the add-on.
After you install an add-on, MATLAB manages the MATLAB path for you. Therefore,
you can start using an add-on without making adjustments to your desktop environment.
Note: When installing a MathWorks product add-on, additional required products are
installed automatically. For all other add-ons, you must install additional required
products manually.
To install the add-on manually, double click the add-on installation file in the MATLAB
Current Folder browser. An installer launches to guide you through the installation
process.
Valid installation files include .mltbx files (toolboxes), .mlappinstall files (apps), and
.mlpkginstall files (hardware support packages).
Related Examples
• “Manage Your Add-Ons” on page 8-3
8-2
Manage Your Add-Ons
• Open the installed location for add-ons installed in the add-ons installation folder.
• Open documentation for MathWorks products.
• View additional details such as a list of included files for apps and toolboxes.
• Uninstall add-ons.
The Add-On Manager displays all add-ons that are properly installed in the add-ons
installation folder, as well as MATLAB products and hardware support packages. If you
have an app or toolbox installed prior to R2015b, import it for use with R2015b and later
by opening the Add-On Manager and clicking Import.
To run an app after you install it, go to the Apps tab and expand the apps gallery by
clicking the down arrow to the far right. Then, navigate to your installed app and
click the icon. Custom apps that you write or receive from someone else appear in the
My Apps section. You can run multiple custom apps concurrently, including multiple
instances of the same app.
1 On the Home tab, in the Environment section, click Preferences > MATLAB
> Add-Ons.
2 In the Installation Folder field, specify a folder name to which you have write
access.
8-3
8 Add-Ons
Note: If you change your installation folder, add-ons installed in the previously selected
folder are no longer accessible from within MATLAB.
Related Examples
• “Get Add-Ons” on page 8-2
8-4
9
Internationalization
The locale setting defines the language of your user interface and the display formats for
information like time, date, and currency. MATLAB uses the user-specified locale on all
platforms.
If MATLAB does not correctly display characters in your language, you might have a
locale setting problem. Locale is composed of individual settings which you can control.
Each platform uses different parameters to specify the locale setting. The following terms
are relevant to understanding locale settings.
For example, for the U.S. English locale setting en_US.US-ASCII, en means that
the display language is English. US indicates that time and date displays use U.S.
conventions. US-ASCII is the coded character set (codeset) used to display text.
• character set — Set of characters that make up a language used by a region. The
MATLAB supported character set is the character set specified by the user locale
setting.
• codeset — Abbreviation for coded character set. A set of characters with a unique
numerical value assigned to each character.
• encoding — Scheme for assigning numerical values to a character set to create a
codeset.
• 7-bit ASCII — Either the codeset or the characters contained in that codeset. There
are 128 characters, which include letters, digits, symbols, control characters, and
graphics characters. The term ASCII in MathWorks documentation is the same as 7-
bit ASCII.
• Unicode — Character codeset. Excerpt from the unicode.org website: “Unicode®
provides a unique number for every character, no matter what the platform, no
matter what the program, no matter what the language.”
• user locale setting — Setting on your computer that specifies the locale that you
want to use when running MATLAB. If your user-specified locale is not supported,
MATLAB uses the default locale en_US_POSIX.US-ASCII.
9-2
Locale Settings for MATLAB Process
• system locale setting — Setting on Microsoft Windows platforms. The user locale and
system locale must be the same value. If these values are not the same, you might see
garbled text or incorrectly displayed characters.
• i18n — Short for the word internationalization, where 18 stands for the number
of letters between the letters i and n.
Related Examples
• “Set Locale on Windows Platforms” on page 9-5
• “Set Locale on Mac Platforms” on page 9-7
• “Set Locale on Linux Platforms” on page 9-8
9-3
9 Internationalization
• MATLAB C/C++ and Fortran engine library functions and the loadlibrary function
cannot find files located in folder names that contain non 7-bit ASCII characters.
• MATLAB C/C++ and Fortran engine library functions and the calllib function used
to call C library functions cannot convert Unicode-compatible input arguments of type
char* to MATLAB character arrays.
• The matlab.wsdl.createWSDLClient function cannot read non 7-bit ASCII
characters in Web Services Description Language (WSDL) documents.
When you have a file containing text that has characters in a different encoding than
that of your platform, when you save or publish your file, MATLAB displays those
characters as garbled text.
9-4
Set Locale on Windows Platforms
MATLAB does not support every locale setting. If your locale is not supported, MATLAB
uses the default locale en_US_POSIX.US-ASCII, also known as C locale.
When you change the system locale, restart your system; otherwise, you might see
unexpected behaviors.
1 From Clock, Language, and Region, select Change date, time or number
formats.
2 On the Formats tab, select a target locale from the Format drop-down list and then
click Apply. This action sets the user locale.
3 On the Administrative tab, click the Change system locale... button.
4 Select a target locale from the Current system locale drop-down list. This action
sets the system locale.
5 Exit each dialog box by clicking the Ok buttons.
6 Restart the system.
User Locale
1 From the Control Panel, select Clock, Language, and Region > Region.
2 Open Formats tab.
3 Select a target locale from the Format drop-down list.
System Locale
1 From the Control Panel, select Clock, Language, and Region > Region.
9-5
9 Internationalization
1 Select Start > Control Panel > Clock, Language, and Region > Region and
Language.
2 Open Formats tab.
3 Select a target locale from the Format drop-down list.
System Locale
1 Select Start > Control Panel > Clock, Language, and Region > Region and
Language.
2 Open Administrative tab.
3 Look in the Language for non-Unicode programs section.
4 Click Change system locale... button.
5 Select a target locale from the Current system locale drop-down list.
6 Restart the system.
9-6
Set Locale on Mac Platforms
If you customize the locale setting, MATLAB ignores the customized portion. MATLAB
ignores the LANG environment variable and the Terminal application locale setting.
MATLAB does not support every locale setting. If your locale is not supported, MATLAB
uses the default locale en_US_POSIX.US-ASCII, also known as C locale.
1 In the Language & Region dialog box, either drag an existing item to the top of the
Preferred languages list, or select the + button to add a language and then drag
the language to the top.
2 MATLAB detects the latest setting; you do not need to restart your system.
Changing the preferred language might change the locale to a value that MATLAB does
not support. When this happens, you might see garbled text or incorrect characters. To
fix this problem, change the Format language value:
1 In the Language & Region dialog box, change the Preferred languages value to
the original value.
2 Click the Advanced... button, and make note of the Format language value.
3 Click OK.
4 Change the Preferred languages value back to your preferred language.
5 Click the Advanced... button again. If the Format language value changed,
reselect the original language value.
9-7
9 Internationalization
MATLAB does not support every locale setting. If your locale is not supported, MATLAB
uses the default locale en_US_POSIX.US-ASCII, also known as C locale.
More About
• “Numbers Display Period for Decimal Point” on page 9-12
9-8
Unexpected Behavior on Mac Platforms
MATLAB ignores the LANG environment variable and the Terminal application locale
setting.
Related Examples
• “Set Locale on Mac Platforms” on page 9-7
9-9
9 Internationalization
Related Examples
• “Set Locale on Windows Platforms” on page 9-5
9-10
datenum Might Not Return Correct Value
name: 'license_agreement.txt'
date: '10-May-2015 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;
See Also
dir
9-11
9 Internationalization
MATLAB uses a period for a decimal point, regardless of the format specified by the user
locale. For example, the value of pi can be displayed as 3,1416 or 3.1416, depending on
the format used by a locale. MATLAB always displays 3.1416.
The MATLAB language reserves the use of commas to the cases described in the Symbol
Reference topic.
More About
• Symbol Reference: Comma
9-12
File or Folder Names Incorrectly Displayed
On Mac platforms, for files and folders used by MATLAB, characters in the file or folder
name must be in the 7-bit ASCII character set.
More About
• “Locale Settings for MATLAB Process” on page 9-2
9-13
9 Internationalization
Script Compatibility
Non-7-bit ASCII characters in plain text files, such as MATLAB scripts or functions,
created with one locale setting might not be compatible with a different locale setting.
This can happen when a script written on a Windows platform is run on a Linux
platform, because the platforms use different default locale settings.
For example, if you create a script with the ja_JP.UTF-8 locale setting on a Linux
system, the script might not be compatible when executed on a Windows platform with
the Japanese_Japan.932 locale setting.
9-14
MATLAB Desktop Language Preference
Most desktop elements and Apps use the language selected in the Desktop language
preference. However, system dialog messages, such as file selectors or color pickers, use
the operating system display language.
More About
• “General Preferences” on page 2-51
9-15