Matlab
Matlab
R2018b
How to Contact MathWorks
Phone: 508-647-7000
v
Specifying Java Startup Options . . . . . . . . . . . . . . . . . . . . . . . . 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
Optimize Desktop Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11
Desktop Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11
Document Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14
Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-39
Set Preferences for MATLAB . . . . . . . . . . . . . . . . . . . . . . . . 2-39
Where MATLAB Stores Preferences . . . . . . . . . . . . . . . . . . . 2-39
Preferences MATLAB Uses When Multiple Releases Are
Installed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-40
General Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42
Confirmation Dialog Boxes Preferences . . . . . . . . . . . . . . . . 2-43
vii
Source Control Preferences . . . . . . . . . . . . . . . . . . . . . . . . . 2-45
Keyboard Shortcuts Preferences . . . . . . . . . . . . . . . . . . . . . . 2-45
Colors Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-46
Colors Programming Tools Preferences . . . . . . . . . . . . . . . . . 2-47
Comparison Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-48
Toolbars Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-49
Entering Commands
3
Enter Statements in Command Window . . . . . . . . . . . . . . . . . . 3-2
viii Contents
Delimiter Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-25
Code Suggestions and Completions . . . . . . . . . . . . . . . . . . . 3-25
Function Syntax Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28
ix
Workspace Browser and Variable Editor
5
Create and Edit Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Create Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
View Workspace Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
View Variable Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
Edit Variable Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5
Resize or Reshape Variables . . . . . . . . . . . . . . . . . . . . . . . . . 5-10
Copy, Rename, and Delete Variables . . . . . . . . . . . . . . . . . . . 5-11
Navigate Variable Contents . . . . . . . . . . . . . . . . . . . . . . . . . 5-12
x Contents
Compare and Merge MAT-Files . . . . . . . . . . . . . . . . . . . . . . . 6-19
Compare Binary Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-22
Comparison Report Tools and Options . . . . . . . . . . . . . . . . . 6-23
Source Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-24
xi
Use Search Path with Different MATLAB Installations . . . . . 6-55
Editor Preferences
7
Editor/Debugger Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2
General Preferences for the Editor/Debugger . . . . . . . . . . . . . 7-2
Editor/Debugger Display Preferences . . . . . . . . . . . . . . . . . . . 7-4
Editor/Debugger Tab Preferences . . . . . . . . . . . . . . . . . . . . . . 7-5
Editor/Debugger Language Preferences . . . . . . . . . . . . . . . . . 7-6
Editor/Debugger Code Folding Preferences . . . . . . . . . . . . . . 7-9
Editor/Debugger Backup Files Preferences . . . . . . . . . . . . . . 7-10
Editor/Debugger Autoformatting Preferences . . . . . . . . . . . . 7-11
Editor/Debugger Autocoding Preferences . . . . . . . . . . . . . . . 7-13
xii Contents
Add-Ons
8
Get Add-Ons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Install Add-Ons Manually . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3
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
xiii
Script Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-15
MATLAB Online
10
Share and Restore Files in MATLAB Online . . . . . . . . . . . . . . 10-2
Share Folders in MATLAB Online . . . . . . . . . . . . . . . . . . . . . 10-2
Restore Previous Versions of Files in MATLAB Online . . . . . . 10-4
xiv Contents
1
When you start MATLAB, it automatically adds the userpath folder to the search path.
MATLAB also reopens any desktop components that were open when you last shut down.
The MATLAB startup folder is the folder you are in when you get the MATLAB prompt. To
change the default startup folder, see “MATLAB Startup Folder” on page 1-20.
If you have trouble starting MATLAB, then see MATLAB Installation, Activation & Startup
Help.
With this option, the startup folder is the last working folder from the previous MATLAB
session or the custom path specified in the Initial working folder preference described
in “General Preferences” on page 2-42.
You also can specify a custom startup folder in the MATLAB shortcut icon using the Start
in field. However, this technique is the same as setting a custom path in the Initial
1-2
Start MATLAB on Windows Platforms
working folder preference. If you enter an invalid path in the Start in field, then the
startup folder is unpredictable. To set a custom path in the Start in field:
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 Start in field, type the full path to a folder on your system, and then click OK.
The startup folder is the folder in which you run the matlab command. To use the folder
specified by the Initial working folder preference, type:
matlab -useStartupFolderPref
!matlab
For example, using the Windows Explorer tool, double-click a file with a .m extension.
MATLAB starts and opens the file in the MATLAB Editor.
For more information, see “Associate Files with MATLAB on Windows Platforms” on page
1-6.
1-3
1 Startup and Shutdown
See Also
matlab (Windows) | userpath
More About
• “Specify Startup Options” on page 1-25
• “MATLAB Startup Folder” on page 1-20
• “General Preferences” on page 2-42
• “Associate Files with MATLAB on Windows Platforms” on page 1-6
• MATLAB Installation, Activation & Startup Help
1-4
Speed Up MATLAB Startup
See Also
1-5
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, then 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, then you
must manually reassociate the type with each new installation of MATLAB. If you want to
return to the default behavior, then 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.
See Also
More About
• “Associate .mat Files with MATLAB” on page 1-7
1-6
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, then 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, then uninstall every
MATLAB that is manually associated to any MATLAB file type. Then reinstall the latest
MATLAB release.
1-7
1 Startup and Shutdown
See Also
More About
• “Associate Files with MATLAB on Windows Platforms” on page 1-6
1-8
Start MATLAB on Linux Platforms
After starting MATLAB, the desktop opens. Desktop components that were open when you
last shut down MATLAB reopen. If the DISPLAY environment variable is not set or is
invalid, then the desktop does not display.
The MATLAB startup folder is the folder you are in when you get the MATLAB prompt. To
change the default startup folder, see “MATLAB Startup Folder” on page 1-20.
If you have trouble starting MATLAB, then see MATLAB Installation, Activation & Startup
Help.
Startup Folder
On Linux platforms, the default startup folder is the folder from which you started
MATLAB.
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. To specify a different folder for userpath, and for other options,
call the MATLAB userpath function.
The ssh command pipes hello.m to MATLAB running on the remote host
local.foo.com. The -nodisplay option starts MATLAB without the desktop.
1-9
1 Startup and Shutdown
See Also
matlab (Linux) | matlabroot | userpath
More About
• “Specify Startup Options” on page 1-25
• “MATLAB Startup Folder” on page 1-20
• “General Preferences” on page 2-42
• MATLAB Installation, Activation & Startup Help
1-10
Start MATLAB on Mac Platforms
When you start MATLAB, it automatically adds the userpath folder to the search path.
MATLAB also reopens any desktop components that were open when you last shut down.
The MATLAB startup folder is the folder you are in when you get the MATLAB prompt. To
change the default startup folder, see “MATLAB Startup Folder” on page 1-20.
If MATLAB fails to start due to a problem with required system components such as Java®
software, then diagnostics run automatically. The software advises you of the problem and
offers suggestions to correct it. For information about other startup problems, see
MATLAB Installation, Activation & Startup Help.
The startup folder is the last working folder from the previous MATLAB session or the
custom path specified in the Initial working folder preference described in “General
Preferences” on page 2-42.
matlabroot/bin
1-11
1 Startup and Shutdown
• Start MATLAB.
./matlab
See Also
matlab (Mac) | matlabroot | userpath
More About
• “Specify Startup Options” on page 1-25
• “MATLAB Startup Folder” on page 1-20
• “General Preferences” on page 2-42
• MATLAB Installation, Activation & Startup Help
1-12
Exit MATLAB
Exit MATLAB
In this section...
“Ways to Quit or Exit” on page 1-13
“Confirm Exiting” on page 1-13
“Run Script When Exiting” on page 1-14
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-13
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.
There are two sample files in matlabroot/toolbox/local that you can use as the
basis for your own finish.m file:
See Also
exit | finish | quit
More About
• “Confirmation Dialog Boxes Preferences” on page 2-43
• “Recovering Data After Abnormal Termination” on page 1-15
• “Error Log Reporting” on page 1-16
• MATLAB Installation, Activation & Startup Help
1-14
Recovering Data After 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, then you might be able to recover output.
• If you saved the workspace to a MAT-file during the session, then 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, then you should be able to recover changes you
made to files you had not saved. To recover, open the backup version filename.asv
in the Editor. Then save it as filename.m to use the last good version of filename.
• If you were in a Simulink® session when a segmentation violation occurred, and you
have the Simulink Autosave Options preference selected, then 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-16
• “Save Files”
More About
• “Commonly Used Startup Options” on page 1-23
1-15
1 Startup and Shutdown
dir(fullfile(tempdir,'matlab_crash_dump.*.*'))
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, then 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-16
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, then click Details.
2 Click Close to terminate MATLAB.
3 Restart MATLAB. If the Error Log Reporter dialog box opens, then select the option
to send a report to MathWorks.
1 If you want to view the stack trace for the problem, then 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.
Caution Because the internal state of MATLAB might be corrupted, do not save
existing files to the same file name. Instead, specify a new file name. The information
in the new file might be corrupted or incomplete.
4 Exit MATLAB immediately after saving because any further usage would be
unreliable.
5 Restart MATLAB. If the Error Log Reporter dialog box opens, then select the option
to send a report to MathWorks.
1-17
1 Startup and Shutdown
• MATLAB startup folder, if starting MATLAB from an operating system prompt. For
more information, see “MATLAB Startup Folder” on page 1-20.
• If there is no java.opts file in the startup folder, then MATLAB checks the
matlabroot/bin/arch folder. matlabroot is the output of the matlabroot
function. arch is the output of the MATLAB computer('arch') function, for
example glnxa64.
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
“Locate Native Method Libraries”.
• To override built-in options that MATLAB specifies to Java at startup. Options in
java.opts are appended to the end of the built-in list. Whether or not these
additional options override built-in options is JVM-dependent and can change between
Java versions. To see what options MATLAB provides to Java, run this command:
java.lang.management.ManagementFactory.getRuntimeMXBean.getInputArguments
See Also
matlab (Linux) | matlab (Mac)
1-18
See Also
Related Examples
• “Java Heap Memory Preferences”
• “Static Path”
• “Locate Native Method Libraries”
More About
• “MATLAB Startup Folder” on page 1-20
1-19
1 Startup and Shutdown
Note If a startup.m file changes the current folder, then 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.
For more information, see “Start MATLAB on Windows Platforms” on page 1-2.
1-20
MATLAB Startup Folder
For more information, see “Start MATLAB on Mac Platforms” on page 1-11.
On Linux platforms, the default startup folder is the folder from which you started
MATLAB.
For more information, see “Start MATLAB on Linux Platforms” on page 1-9.
Alternatively on Windows platforms, specify the initial working folder in the MATLAB
shortcut icon. For more information, see “Select MATLAB Icon” on page 1-2.
• You can store the MATLAB files you work with in one folder, such as Documents/
MATLAB.
• 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, the software automatically creates
the userpath folder if it does not exist.
1-21
1 Startup and Shutdown
See Also
startup
Related Examples
• “Start MATLAB on Windows Platforms” on page 1-2
• “Start MATLAB on Mac Platforms” on page 1-11
• “Start MATLAB on Linux Platforms” on page 1-9
More About
• “General Preferences” on page 2-42
1-22
Commonly Used Startup Options
1-23
1 Startup and Shutdown
See Also
matlab (Linux) | matlab (Mac) | matlab (Windows)
1-24
Specify Startup Options
matlab -nosplash
On Windows platforms, you can precede a startup option with either a hyphen (-) or a
slash (/). For example, -nosplash and /nosplash are equivalent.
To use startup options for the MATLAB shortcut icon, 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-25
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:
addpath /home/myname/mytools
To change the current folder on startup to mytools, set the Initial working folder
value, described in “General Preferences” on page 2-42, to:
/home/myname/mytools
which startup
If MATLAB finds a startup.m file, then it displays the path to the file.
1-26
See Also
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.
#!/usr/local/bin/perl
$val = 10;
system('matlab -r "test(' . ${val} . ')"');
2 Invoke the Perl script at the prompt using a Perl interpreter.
For more information, see the -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-23
• “What Is the MATLAB Search Path?” on page 6-48
1-27
1 Startup and Shutdown
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 the matlabroot folder. This folder is 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.
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 folder
1-28
Toolbox Path Caching in MATLAB
tree. If you keep your files in the matlabroot folder, then they might be overwritten
when you install a new version of MATLAB.
When you add files to the matlabroot folder, 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 the matlabroot folder.
When you add or remove files in the matlabroot folder by some other means, MATLAB
might not recognize those changes. For example, when you:
and then attempt to use one of the new files,MATLAB displays this message:
Update the cache so MATLAB recognizes the changes you made in the matlabroot
folder.
Function Alternative
To update the cache, use rehash toolbox. To update both the cache and the cache file,
use rehash toolboxcache. For more information, see rehash.
1-29
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
2-2
Change Fonts
Workspace browser
Variables editor
Function Browser
Custom fonts SansSerif, Plain, 10 point Profiler (and Code Analyzer
messages, Function Browser help,
and Supplemental Software help)
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.
1. UNIX is a registered trademark of The Open Group in the United States and other countries.
2-3
2 Desktop
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
• 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
See Also
Related Examples
• “Set Print Options” on page 2-27
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 Live
Editor, 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”.
Changes to the Code Analyzer color preferences do not apply in the Live Editor.
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. Moving the quick access toolbar is not supported in MATLAB Online™.
To add a toolstrip item to the quick access toolbar, right-click the button, and then select
Add to Quick Access Toolbar. You also can select from a list of common items by going
to the quick access toolbar and clicking the button. To remove an item from the quick
access toolbar, right-click the item icon and select Remove from Quick Access Toolbar.
To arrange buttons in the quick access toolbar, drag the button icon to the desired
location.
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
See Also
More About
• “Use Keyboard Shortcuts to Navigate MATLAB” on page 2-16
• “Customize Keyboard Shortcuts” on page 2-20
2-10
Optimize Desktop Layout
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. To
optimize the MATLAB Online desktop, see “Desktop Layout in MATLAB Online” on page
2-13.
Action Procedure
Minimize or restore the MATLAB To minimize, at the lower right corner of the
toolstrip
toolstrip, click .
2-11
2 Desktop
Action Procedure
Minimize a tool On the title bar of a docked tool, click , and then
select Minimize .
2-12
Optimize Desktop Layout
Action Procedure
Move undocked tools back to the At the upper right of the tool panel, click , and
desktop then select Dock.
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 MATLAB stores the arrangements you save as XML
files in the preferences folder on page 2-40 for
• Rename or delete a saved MATLAB. The layout last used in a session is
arrangement 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-25. Startup options are not available MATLAB Online.
MATLAB Online provides access to MATLAB from a standard web browser. To change the
desktop layout in MATLAB Online go to the Home tab, click Layout, and then select an
option. To move an individual tool, drag the tool by its title bar to a new location. You
cannot undock a tool in MATLAB Online.
To minimize a tool, collapse the panel in which the tool resides. For example, if the
MATLAB Online desktop is in the default layout with the Current Folder browser in the
left side panel, click the button at the bottom left corner of the panel to collapse the
panel. To restore the panel, click the button.
If the left or right side panel contains multiple tools, you can minimize an individual tool
by clicking the button to the left of the tool's title bar. Multiple tools in the bottom
panel display as tabs and cannot be minimized.
2-13
2 Desktop
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
Change the tabs position On the View tab, in the Document Tabs
section, click Tabs Position , and then
select an option.
2-14
Optimize Desktop Layout
Action Procedure
Undock a document Right-click the document tab and then
select Undock.
Close and save the document currently Click .
displaying
Close a document in the Editor without Click Ctrl + .
saving
2-15
2 Desktop
This table describes the actions and related keyboard shortcuts useful for navigating
MATLAB without a mouse.
2-16
Use Keyboard Shortcuts to Navigate MATLAB
You cannot customize most of these shortcuts. For information about customizable
keyboard shortcuts and how to view and modify them, see “Customize Keyboard
Shortcuts” on page 2-20.
MATLAB Online
MATLAB Online provides access to MATLAB from a standard web browser. Because
MATLAB Online runs in a browser, navigation using the keyboard is slightly different.
This table describes the actions and related keyboard shortcuts useful for navigating
MATLAB Online without a mouse.
2-17
2 Desktop
This table describes several of these actions and their related keyboard shortcuts. For
additional keyboard shortcuts, see the documentation for a specific tool or feature.
You cannot customize these shortcuts. For information about customizable keyboard
shortcuts and how to view and modify them, see “Customize Keyboard Shortcuts” on page
2-20.
2-18
See Also
See Also
More About
• “Customize Keyboard Shortcuts” on page 2-20
• “Rerun Favorite Commands” on page 3-15
• “Access Frequently Used Features” on page 2-9
2-19
2 Desktop
There are several ways you can modify the current set of keyboard shortcuts. You can:
To view or modify the current set of keyboard shortcuts, use the Keyboard Shortcuts
Preferences panel. To open the Keyboard Shortcuts Preferences panel, go to the Home
tab, and in the Environment section, click Preferences. Then, select MATLAB >
Keyboard > Shortcuts.
For actions that are not performed with a menu item, to find keyboard shortcuts, open the
Keyboard Shortcuts Preferences panel. Then, in the search box, enter the name of the
tool or action for which you want to see the keyboard shortcuts. For example, type
Editor clear to find the keyboard shortcut for clearing selected text in the Editor.
2-20
Customize Keyboard Shortcuts
To view the shortcuts for an action, select the action name. For example, select Clear
Selection. MATLAB displays the keyboard shortcuts for the selected action. For example,
the keyboard shortcut for the Clear Selection action in the Editor is the Escape key.
You can create a list of all the keyboard shortcuts in the current set by copying them to
the clipboard and pasting them in a text file or spreadsheet application, such as Microsoft
Excel®. For the best formatting, use a spreadsheet application. To copy all the keyboard
shortcuts, open the Keyboard Shortcuts Preferences panel. Click the Actions button
and from the drop-down menu, choose Copy to Clipboard. Paste the data into the
desired application.
2-21
2 Desktop
1 Open the Keyboard Shortcuts Preferences panel and, in the search box, type an
existing keyboard shortcut or the name of an action, tool, or menu.
For example, you can type Ctrl+R (shortcut), Delete (action), Command Window
(tool), or File (menu).
You can enter most keyboard shortcuts by either pressing keystrokes or typing the
key names. If using keystrokes for a keyboard shortcut does not work, try typing the
key names instead. For example, if pressing the Ctrl key and then R does not work,
try typing the text Ctrl+R.
MATLAB displays the list of matching actions for which you can customize or define a
keyboard shortcut. If you specify the name of a tool, MATLAB displays actions
associated with the tool or menu, as well as any action names that contain the
specified text.
2 Select the name of the action for which you want to define or modify a keyboard
shortcut.
3
Click the Add button .
2-22
Customize Keyboard Shortcuts
4 Specify the keystrokes you want to use for the keyboard shortcut.
A keystroke can be a single key or the combination of a modifier (Alt, Shift, or Ctrl)
and another key. Specify a keystroke by performing it, not by typing the names of the
keys character by character. For example, press the Ctrl key and the Y key. Do not
type C-t-r-l-+-Y.
To specify multiple keystrokes for one action, or to limit the number of keystrokes for
an action, click the down arrow next to the key icon in the Shortcuts box. Then,
select either Limit to 1 keystroke, Limit to 2 keystrokes, or Limit to 3
keystrokes. For example, to specify Ctrl+Y, Shift+Z, F9 as the three keystrokes
for an action, select Limit to 3 keystrokes and then type the keystrokes.
5 In the Tools with shortcut column, click the down arrow and select which tools you
want to assign the keyboard shortcut to.
6 Evaluate and resolve any conflicts, indicated by the and icons. The icon
indicates that two different actions within the same tool have the same shortcut. The
icon indicates that two different actions in two different tools have the same
shortcut.
2-23
2 Desktop
To delete a keyboard shortcut for a selected action, select the keyboard shortcut that you
want to delete and click the Delete button .
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,
click the Actions button and select Undo Modifications to <Set Name> Default
Set (modified), where <Set Name> is the name of the modified default set.
Note Undoing modifications reverts all keyboard shortcuts changes that you made to the
set. You cannot undo modifications on a shortcut-by-shortcut basis.
There are some actions and tools for which you cannot change the keyboard shortcuts.
Actions for which the keyboard shortcut cannot be customized do not appear when you
search for them in the MATLAB Keyboard Shortcuts Preferences panel. Examples of these
actions include canceling the current action (Esc), interrupting MATLAB execution (Ctrl
+C), and some of the navigational actions described in “Use Keyboard Shortcuts to
Navigate MATLAB” on page 2-16.
In addition, you cannot change the keyboard shortcuts associated with these 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-24
Customize Keyboard Shortcuts
By default, MATLAB uses the keyboard shortcut settings for your current platform. To
select a different set of keyboard shortcuts, open the Keyboard Shortcuts Preferences
panel and, in Active settings, select from the available options. To use a keyboard
shortcut settings file that is on your system but not in the Active settings list, select
Browse... to find and select the desired file.
This table lists the keyboard shortcut settings files installed with MATLAB.
You also can download keyboard shortcut settings files from File Exchange. For example,
to restore the MATLAB default keyboard shortcuts that were in place for MATLAB Version
7.9 (R2009a) and earlier releases, go to File Exchange and search for MATLAB Desktop
R2009a Default Keyboard Shortcut sets. Download and extract the set and then
select it as the active settings file. A valid keyboard shortcut settings file appears with a
keyboard key icon .
1 Open the Keyboard Shortcuts Preferences panel and click the Actions button .
2 From the drop-down menu, choose the set of keyboard shortcuts to which you want
to compare the current set.
3 The Comparison Tool opens and displays the two keyboard shortcut sets side-by-side.
For more information about how to read the results, see “Compare and Merge Text”
on page 6-11.
2-25
2 Desktop
Saving a set of keyboard shortcuts to a settings file is useful if you want to:
• Save the changes you make to a default keyboard shortcut set to a new set.
• Use a set of customized keyboard shortcuts on another system running MATLAB.
• Overwrite a previously saved set of keyboard shortcuts.
• Share a set of keyboard shortcuts with others, for example, on File Exchange.
To save a keyboard shortcut settings file, open the Keyboard Shortcuts Preferences panel.
Then, click the Actions button and select Save As. MATLAB saves the file as
an .xml file in the folder that you specify.
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).
To delete a previously saved set of keyboard shortcuts, open the Keyboard Shortcuts
Preferences panel and in Active settings, select the set of keyboard shortcuts that you
want to delete. Click the Actions button and select Delete filename, where
filename is the name of a keyboard shortcut set you want to delete. You cannot delete
default keyboard shortcut sets, such as Windows Default Set.
See Also
More About
• “Use Keyboard Shortcuts to Navigate MATLAB” on page 2-16
• “Rerun Favorite Commands” on page 3-15
• “Access Frequently Used Features” on page 2-9
2-26
Set Print Options
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-27
2 Desktop
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-28
Set Print Options
Tip You can change the font that a desktop tool uses. On the Home tab, in the
Environment section, click Preferences > Fonts > Custom.
2-29
2 Desktop
2-30
Web Browsers and MATLAB
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-31
2 Desktop
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 on page 2-33.
To display a Web page or any file type in the MATLAB Web browser:
2-32
Web Browsers and MATLAB
Examples of acceptable formats for the host are: 172.16.10.8 and ourproxy. For
the port, enter an integer only, such as 22. If you do not know the values for your
proxy server, ask your system or network administrator for the information.
If your proxy server requires a user name and password, select the Use a proxy with
authentication check box. Then enter your proxy user name and password.
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-33
2 Desktop
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-32 for more
information.
Option Description
Update Current Displays a list of all your MathWorks licenses on this computer, with
Licenses their status. When you select a license and click Update Selected
License, MATLAB contacts MathWorks to retrieve the most current
version of the License File for the license. The update process
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.
2-34
See Also
Option Description
Deactivate Displays a list of all your MathWorks licenses on this computer, with
Software 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.
See Also
More About
• “Introduction to Installation and Licensing” (Installation, Licensing, and Activation)
2-35
2 Desktop
Release notes document new features and changes, bug reports, and compatibility
considerations.
6 Decide whether you want to update to the most recent version.
2-36
Macintosh Platform Conventions
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.
2-37
2 Desktop
4 Press Go.
To open a file with a MATLAB command, such as edit, specify the full path of the
MATLAB root folder. For example:
edit(fullfile(matlabroot,'/toolbox/matlab/demos/lotka.m'))
2-38
Preferences
Preferences
Preferences take effect immediately. They remain persistent across sessions of MATLAB.
Most preferences are not available in MATLAB Online, except selected Command Window
and Confirmation Dialog preferences.
Function Alternative
You can open the Preferences dialog box using the preferences function.
You also can access and set some MATLAB options programmatically using settings. For
more information, see “Access and Modify Settings”.
On macOS and iOS, the folder might be in a hidden folder. If so, to access the hidden
folder:
2-39
2 Desktop
You must have write access to the preferences folder. Otherwise, MATLAB generates an
error in the Command Window when you try to change preferences. MATLAB also can
generate an error if the preferences folder is hidden.
In some situations, if MATLAB is unable to create or use the preferences folder when
starting up, it creates a temporary preferences folder. If a preferences folder exists for a
previous release, MATLAB copies the preference files from that release to the temporary
preferences folder. Otherwise, MATLAB creates the default preference files for the
current release. MATLAB continues to use the temporary preferences folder until the
issue is resolved.
If you make changes to preferences while MATLAB is using the temporary preferences
folder, the preferences persist across sessions. Once the issue preventing MATLAB to
access the preferences folder is resolved though, MATLAB copies the preference files
from the previous release or creates the default preference files for the current release.
Any changes made to the preferences while using the temporary preference folder are
lost.
Each version of MATLAB can have a temporary preferences folder. MATLAB does not
migrate preferences from the temporary preferences folder across releases.
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-40
Preferences
• 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 for a given release.
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 a preference folder for the given
of MATLAB release exists, make sure that the folder
is empty before starting up.
• If a preference folder for the given
release does not exist and one or more
of the preference folders for the
previous three releases do exist, create
an empty preferences folder for the
given release.
2-41
2 Desktop
To Use: Do This:
All the preference files from a release of Ensure that the preferences folder exists
MATLAB up to three releases preceding the for that previous release. Delete the entire
release you plan to start up or sign into. preferences folder for each release after
the release you want to migrate from,
including the folder for the release of
MATLAB you plan to start up or sign into.
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 or sign into.
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 the last working folder from your previous
MATLAB session, or specify the full path to a
folder on your system. For more information, see
“MATLAB Startup Folder” on page 1-20.
2-42
Preferences
Preference Usage
Deleting files Select an option to specify what MATLAB does
with files you delete using the delete function.
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, and some options are
not available in MATLAB Online.
2-43
2 Desktop
For details, see “Save and Load Workspace Variables” on page 5-16.
2-44
Preferences
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 this table.
If you use source control integration through the MATLAB Current Folder Browser,
MATLAB might crash when you view or commit changes.
Preference Usage
Active settings Select or import a set of predefined
keyboard shortcuts.
2-45
2 Desktop
Preference Usage
Select any one of these options:
Colors Preferences
You can specify the text and background color for desktop tools, as well as colors for
highlighting syntax elements of MATLAB code.
On the Home tab, in the Environment section, click Preferences. Select MATLAB >
Colors. Then, set options as described in the table below.
2-46
Preferences
Preference Usage
Desktop tool colors Specify that desktop tools use the same text and
background colors that your platform uses for other
applications by selecting Use system colors.
On the Home tab, in the Environment section, click Preferences. Select MATLAB >
Colors > Programming Tools. Then, set options as described in the table below.
2-47
2 Desktop
Preference Usage
Code analyzer colors • Warnings—Specifies the color Code Analyzer uses to identify
code in the Editor for which there are warning messages.
• Autofix highlight—Specifies the color Code Analyzer uses to
identify code in the Editor for which there is an automatic fix.
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.
2-48
Preferences
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.
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” (Simulink).
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.
2-49
2 Desktop
Preference Usage
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.
See Also
prefdir
More About
• “Access and Modify Settings”
2-50
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 connect Provide information that MATLAB needs to access the internet
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-51
2 Desktop
Preference Usage
Test connection Ensure that your settings work.
2-52
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 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.
x =
1.3333 0.0000
• compact — Suppresses the display of blank lines.
format loose
format compact
Note Line spacing display options do not apply in the Live Editor.
3-7
3 Entering Commands
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
3 Click OK.
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
In this section...
“Find Text in the Command Window” on page 3-12
“Find Text in the Command History Window” on page 3-14
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.
3-12
Find Text in Command Window or History
You can also perform an incremental search in the Command Window using keyboard
shortcuts.
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.
3-13
3 Entering Commands
The incremental search field disappears. The cursor remains at the position where
the text was last found, with the search text highlighted.
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
Rerun Favorite Commands
To run a favorite command, on the Home tab, click Favorites and then click the icon for
the desired favorite command. All the statements in the Code field of the Favorite
3-15
3 Entering Commands
Command Editor execute as if you ran those statements from the Command Window,
although they do not appear in the Command History window.
To edit a favorite command, click the icon to the right of the favorite command. To
delete a favorite command, click the icon to the right of the favorite command. You
also can right-click the favorite command and select Edit Favorite or Delete Favorite.
1 On the Home tab, in the Code section, click Favorites and then click New
Category. The Favorite Category Editor dialog box opens.
2 In the Label field, enter a name for the category. For this example, enter My
Favorite Favorites.
3 In the Icon field, select an icon.
4 To add the category to the quick access toolbar, select both the Add to quick access
toolbar and Show label on quick access toolbar options.
5 Click Save.
To change whether a single category or favorite command appears in the quick access
bar, click the and icons to the right of the category or favorite command. To add
all favorite commands to the quick access bar, on the Home tab, right-click Favorites
and select Add to quick access toolbar.
To further configure which favorite commands and categories appear in the quick access
bar, on the Home tab, in the Code section, click Favorites and then click Quick
Access. Adding and configuring favorite commands and categories in the quick access
bar is not supported in MATLAB Online.
3-16
See Also
See Also
More About
• “Customize Keyboard Shortcuts” on page 2-20
• “Set Command History Preferences” on page 3-30
3-17
3 Entering Commands
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-
8.
3-18
Set Command Window Preferences
Preference Usage
Select Set matrix display width to eighty columns to limit the
width of matrix output.
Note If you also select Wrap lines, and the width of the Command
Window is 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.
3-19
3 Entering Commands
Preference Usage
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
for the Command Window or Editor. To enable or disabled tab
completion, on the Home tab, select Preferences > Keyboard.
See Also
More About
• “Change Fonts” on page 2-2
3-20
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
Suggestions and Select Tab key narrows completions to have MATLAB continue to
completions reduce the list of possible names for completions as you type each
additional character and press the Tab key. This option is not
supported in the Live Editor.
3-21
3 Entering Commands
Preference Usage
In the Command Window or Editor sections, select Enable
function hints to have MATLAB display function hints in the
Command Window and/or Editor.
3-22
Set Keyboard Preferences
Preference Usage
Delimiter Matching Specify when and if MATLAB alerts you to matched and mismatched
delimiters. Delimiters include parentheses, brackets, braces, and, in
the Editor only, paired keywords.
3-23
3 Entering Commands
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:
Except for errors, output in the Command Window does not appear with syntax
highlighting.
MATLAB software copies the selection to the Clipboard in RTF format, which many
Microsoft Windows and Macintosh applications support. 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.
You can change syntax highlighting preferences. On the Home tab, in the Environment
section, click Preferences. Select MATLAB > Editor/Debugger > Languages.
Changing syntax highlighting preferences is not supported in MATLAB Online. In the Live
Editor, changing syntax highlighting color preferences is supported, but disabling syntax
highlighting is not supported.
3-24
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 the Live Editor or in
MATLAB Online.
You can change what the delimiter matching indicators are, and when or if they appear.
On the Home tab, in the Environment section, click Preferences. Select MATLAB >
Keyboard. Changing delimiter matching indicator preferences is not supported in the
Live Editor or in MATLAB Online.
3-25
3 Entering Commands
properties, parameters, and options. You can use automatic suggestions and completions
to write commands faster and avoid typographical errors.
The Live Editor automatically displays possible matches as you type. To insert a match in
your script, use the arrow keys to select the name you want, and then press the Tab key.
Press the Esc key to clear the list of possible completions without selecting anything. To
complete names in the Command Window or Editor, type the first few characters of the
name you want to complete, and then press the Tab key. Use the arrow keys to select the
name you want, and then press the Tab key again. In MATLAB Online, the Editor behaves
the same as the Live Editor.
Automatic suggestions and completions are especially useful when completing the names
and values of graphics properties. For example, plot(x,y,'LineStyle','-').
You can also use the suggestions to complete parameter names and options for certain
functions. For example, format('shortEng').
3-26
Check Syntax as You Type
MATLAB does not complete field names of structure arrays defined only within the active
file.
Tip To use the Tab key to add multiple spaces within a statement, first add a space, and
then press Tab. Otherwise, when tab completion is enabled, MATLAB attempts to
complete a name.
To have MATLAB suggest and complete names only after you press the Tab key in the
Live Editor, on the Home tab, in the Environment section, click Preferences. Then,
select MATLAB > Keyboard and in the Suggestions and completions > Live Editor
section, select Show on tab.
To disable suggestions and completions in the Command Window and Editor, in the
Suggestions and completions section, clear Enable tab completion for the desired
tool.
3-27
3 Entering Commands
Function syntax hints appear for both MATLAB installed functions and functions you
create. The syntax hints for MATLAB functions come from the documentation. The syntax
hints for functions you create come 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. For more information about adding help to the functions you create,
see “Add Help for Your Program”.
To use function syntax hints, type a function name with an opening parenthesis. A pop-up
window opens showing the basic syntax for the function. In the Live Editor (and Editor in
MATLAB Online), you can use the drop-down arrow to the right of the syntax to display
all available syntaxes.
You can type an input for any argument that appears in blue. Enter your own input
names, and not the argument names shown in the window. The displayed syntax options
change based on the argument you just entered.
In the Live Editor (and Editor in MATLAB Online), MATLAB displays descriptions for each
argument. Optional arguments are indicated by the (optional) keyword next to the
argument description.
3-28
Check Syntax as You Type
Some function names are overloaded. That is, there are different functions with the same
name that support different types of input. Overloaded functions require that you pass an
object as the first input. When you specify the object name, the syntax hints update to
reflect the correct version of the function, as shown. The Live Editor might not display all
overloads.
Function syntax hints are suggestions only. For detailed information about a function, see
the function reference page in the documentation. To open the documentation for the
function, click the button to the left of the function syntax hint.
To disable function syntax hints in the Command Window and Editor, on the Home tab, in
the Environment section, click Preferences. Then, select MATLAB > Keyboard and
in the Suggestions and completions section, clear Enable function hints for the
desired tool. Disabling function syntax hints is not supported in MATLAB Online.
3-29
3 Entering Commands
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
Set Command History Preferences
Option Usage
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
Favorite Commands Select Don't show to disable showing favorite commands in
the Command History window.
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.
See Also
Command History Window
3-32
4
See Also
doc
4-2
See Also
More About
• “MATLAB Code Examples” on page 4-4
4-3
4 Help and Product Information
Standalone Examples
A standalone example is a readable version of a MATLAB script or live 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.)
To access examples, click Examples at the top of a documentation page. The Help
browser displays the examples for the current product category.
MATLAB includes examples that demonstrate various functionalities. For instance, to view
examples demonstrating plotting in MATLAB, navigate to the MATLAB > Graphics > 2-
D and 3-D Plots category and click Examples at the top of the page.
4-4
MATLAB Code Examples
Each example combines comments, code, and output in a formatted document. If you are
viewing the documentation in MATLAB, you can open the corresponding script or live
script by clicking Open Script or Open Live Script.
If you are viewing the documentation on the web, you can open live script examples using
the Live Editor in a web browser. To open the example, click the Try this Example button
to the right of the example and select Try it in your browser.
Once it is open, run the example by clicking Run . To run the example 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 .
Additional examples, created by members of the MATLAB community, are available at the
File Exchange.
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.
Evaluating a selection from the Help browser is not available in MATLAB Online.
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 “MATLAB Operators and Special Characters”.
• 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
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 translated documentation, you must sign 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
1
On the Home tab, in the Resources section, click Request Support.
2 When requested, sign in using your MathWorks Account email address and password.
If you do not have a MathWorks Account, create one.
4-12
See Also
See Also
External Websites
• 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 https://
www.mathworks.com/help. Viewing the web documentation
requires an internet connection and a MathWorks Account.
4-14
See Also
Preference Usage
Quick Help Display Specify whether help links display content in the Help browser or
in a small window. This preference applies to reference pages or
program help that you access using:
To adjust the font size in the Help browser or MATLAB web browser, use the Ctrl +
Mouse Scroll keyboard shortcut.
See Also
More About
• “Translated Documentation” on page 4-16
4-15
4 Help and Product Information
Translated Documentation
Many MathWorks products have translated documentation in Japanese. In addition, some
features of MATLAB have translated documentation in Korean, simplified Chinese, and
Spanish. Usually, if a product provides translated documentation, the new version of the
product installs the translated documentation from the previous version and the English
documentation for the current version.
For information about documentation in other languages, contact your MathWorks sales
and service office.
If the documentation does not display in the language you want, check the preference
settings using these steps:
The Language preference is only available when your system language is set to
Japanese, Korean, Chinese, or Spanish. 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.
4-16
See Also
Spanish documentation is only available on the web, and is not installed with MATLAB.
See Also
Related Examples
• “Set Locale on Windows Platforms” on page 9-5
• “Set Locale on Linux Platforms” on page 9-9
• “Set Locale on Mac Platforms” on page 9-7
4-17
4 Help and Product Information
4-18
5
Create Variables
The MATLAB workspace consists of the variables you create and store in memory during
a MATLAB session. 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;
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)
5-2
Create and Edit Variables
ans =
0.8415
To view and edit variables, use the Workspace browser and Variables Editor. (Some
editing options are not available in MATLAB Online.)
To open the Workspace browser if it is not currently visible, do either of the following:
• 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. In MATLAB Online, select which columns to
display by right-clicking the Workspace browser title bar and selecting or clearing the
desired column names.
You also can 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. For example, if you have the
variables x, A, and I in your workspace, you can run the who and whos commands to view
your workspace contents:
who
5-3
5 Workspace Browser and Variable Editor
A I x
whos
A 3x3 72 double
I 3x3 72 double
x 1x1 8 double
• Command Window — Type the variable name at the command prompt. For example:
x
x =
5.7100
• Variables editor — In the Workspace browser, double-click a variable name. The
Variables editor opens for that variable.
5-4
Create and Edit Variables
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.
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.
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 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-5
5 Workspace Browser and Variable Editor
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-6
Create and Edit Variables
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
• You cannot edit elements or subsets of multidimensional arrays in the Variables editor.
• You cannot edit tall arrays in the Variables editor.
• When editing strings in the Workspace browser or as part of a structure in the
Variables editor, you must use double quotes to surround the string value.
Tables (including timetables) and structure arrays support additional editing actions.
5-7
5 Workspace Browser and Variable Editor
5-8
Create and Edit Variables
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.
5-9
5 Workspace Browser and Variable Editor
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.
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-10.
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:
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.
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.
5-11
5 Workspace Browser and Variable Editor
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.
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-21.
See Also
Workspace Browser | openvar
5-12
See Also
More About
• “Variable Names”
• “Display Statistics in the Workspace Browser” on page 5-14
• “Workspace and Variable Preferences” on page 5-19
• “Save and Load Workspace Variables” on page 5-16
5-13
5 Workspace Browser and Variable Editor
To display statistics, on the Workspace browser title bar, click , and then select Choose
Columns. Select the statistics you want MATLAB to calculate.
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-14
See Also
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.
See Also
More About
• “Infinity and NaN”
• “Workspace and Variable Preferences” on page 5-19
5-15
5 Workspace Browser and Variable Editor
• To save all workspace variables to a MAT-file, on the Home tab, in the Variable
section, click Save Workspace.
• To save a subset of your workspace variables to a MAT-file, select the variables in the
Workspace browser, right-click, and then select Save As. You also can drag the
selected variables from the Workspace browser to the Current Folder browser.
• To save variables to a MATLAB script, click the Save Workspace button or select the
Save As option, and in the Save As window, set the Save as type option to 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.
You also can save workspace variables programmatically using the save function. For
example, to save all current workspace variables to the file june10.mat, use the
command
save('june10')
To save only variables A and B to the file june10.mat, use the command
save('june10','A','B')
To store fields of a scalar structure as individual variables, use the save function with the
-struct option. This can be useful if you previously loaded variables from a MAT-File
into a structure using the syntax S = load(filename) and want to keep the original
variable structure when saving to a new MAT-File.
To save part of a variable, use the matfile function. This can be useful if you are
working with very large data sets that are otherwise too large to fit in memory. For more
information, see “Save and Load Parts of Variables in MAT-Files”.
5-16
Save and Load Workspace Variables
In MATLAB Online, variables persist between sessions. Saving allows you to clear the
workspace and load variables at a later time. To save variables, use the save or matfile
functions.
To load a subset of 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. You also can
drag the desired variables from the Current Folder browser Details panel of the selected
MAT-file to the Workspace browser.
To load variables saved to a MATLAB script into the workspace, simply run the script.
You also can load saved variables programmatically, use the load function. For example,
load all variables from the file durer.mat
load('durer')
To load part of a variable, use the matfile function. This is useful if you are working with
very large data sets that are otherwise too large to fit in memory. For more information,
see “Save and Load Parts of Variables in 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 avoid
overwriting existing variables, use the load function to load the variables into a
structure. For example, S = load('durer') loads all the variables from the file
durer.mat into the structure S.
5-17
5 Workspace Browser and Variable Editor
Alternatively, 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.
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”.
See Also
load | save
More About
• “MAT-File Versions”
• “Save and Load Parts of Variables in MAT-Files”
5-18
Workspace and Variable Preferences
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. Workspace preferences are not available in
MATLAB Online.
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-19
5 Workspace Browser and Variable Editor
Preference Usage
Multidimensional array formatting Specify how multidimensional arrays are
formatted when saved to a MATLAB script.
5-20
Workspace and Variable Preferences
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-21
5 Workspace Browser and Variable Editor
Preference Usage
Editing Specify where the cursor moves to after you type an
element and press Enter.
Most Variables preferences are not available in MATLAB Online. To show generated code
in the Command Window when performing operations in the MATLAB Online Variables
Editor, select Show MATLAB code for operations.
See Also
More About
• “Create and Edit Variables” on page 5-2
5-22
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 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 browse for a
folder by selecting Browse... or 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.
6-3
6 Managing Files in MATLAB
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.
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.
6-4
See Also
See Also
dir | exist | what | which
More About
• “Find Functions to Use” on page 3-4
• “What Is the MATLAB Search Path?” on page 6-48
6-5
6 Managing Files in MATLAB
You can select files and folders to compare using any of these methods:
• Current Folder browser — Select a file or folder, right-click, and select Compare
Against. Browse to select a second item to compare, or drag and drop a file or folder
from your file browser.
You also can select two files or subfolders, right-click, and select Compare Selected
Files/Folders.
• Editor or Live Editor— Go to the Editor or Live Editor tab, and in the File section,
click Compare. The Comparison tool autopopulates the first file for comparison with
the current open file. Browse to select a second item to compare, or drag and drop a
file or folder from your file browser.
• MATLAB desktop — Go to the Home tab, and in the File section, click Compare.
Browse to select items to compare, or drag and drop the files or folders from your file
browser.
• Command Window — Use the visdiff function. For example, to compare the two
files lengthofline.m and lengthofline2.m using the visdiff function and the
default text comparison, type visdiff('lengthofline.m',
'lengthofline2.m'). MATLAB opens the Comparison tool and displays the
resulting comparison report.
In addition to selecting two files and folder, you also can compare a file with a past
version of itself. To compare a file with the autosave version or the saved version on disk,
click Compare and select Compare with Version on Disk or Save and Compare
6-6
Compare Files and Folders and Merge Files
with Autosave. For more information, see “Compare Files with Autosave Version or
Version on Disk” on page 6-15. These options are not available for live scripts or
functions.
The Comparison tool compares selected items using the default comparison type defined
for the items. For some item types, you can select a different comparison type from the
default. For example, you can choose from a text, binary, file list, or XML comparison. To
change the comparison type, select the files or folders to compare and then select from
the options in the Comparison type menu. The Comparison tool only displays the valid
options for the selected item types.
You cannot change the comparison type for an existing comparison report. To change the
comparison type, start a new comparison.
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. 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.
You can explore the comparison report in different ways depending on the items being
compared:
6-7
6 Managing Files in MATLAB
• Folders, zip files, and Simulink manifests — Compare any combination of folders,
zip files, or Simulink manifests to determine which file and folder names are unique to
each list. You also can identify whether files and folders with the same name have the
same content. For more information, see “Compare Folders, Zip Files, and Simulink
Manifests” on page 6-8.
• Text — Compare and merge lines in two text files (some other applications refer to
this as a file diff operation). For more information, see “Compare and Merge Text” on
page 6-11.
• Live Code — Compare and merge code and text lines in two live code files. For more
information, see “Compare and Merge Live Code” on page 6-15.
• MAT-files — Compare and merge variables in two MAT-files. For more information, see
“Compare and Merge MAT-Files” on page 6-19.
• Binary files — Determine whether the contents of two binary files match. For more
information, see “Compare Binary Files” on page 6-22.
• XML files — Compare XML files with a text comparison or a hierarchical XML
comparison. For more information, see “Compare XML Files” on page 6-25.
• Simulink models — If you have Simulink, compare and merge Simulink models. For
information, see “Model Comparison” (Simulink).
To select items to compare, see “Select the Files or Folders to Compare” on page 6-6.
When selecting items to compare, include subfolder content in the comparison report by
selecting Include subfolders.
6-8
Compare Files and Folders and Merge Files
Explore Differences
When you perform any file list comparison, a new window opens and displays the contents
of the specified lists side by side. This image shows an example comparison report for a
two folder comparison.
The Comparison tool highlights files and subfolders that do not match as described in this
table.
6-9
6 Managing Files in MATLAB
• To sort the results by name, type, size, or last modified timestamp, click the
corresponding column header. For example, click the Type column header to sort by
folder and file type.
• To open a detailed comparison report for items with differing content, click the
compare link next to the item.
• 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 version of the 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. You can click Skip Current to skip the current item or Cancel All to stop
further analysis.
For information about how to further configure the comparison report, see “Comparison
Report Tools and Options” on page 6-23.
To save time when reviewing differences, especially when comparing many subfolders,
you can filter the report. To create a filter, go to the View tab, click the Filter button,
and then select Add/Remove Filter. You can specify filters to ignore certain files and
folders, such as backup files or files created by a revision control system.
For example, to ignore all files and folders in a folder named CVS, type CVS/. To ignore all
files in a folder named CVS, but not ignore subfolders, type CVS/*.
6-10
Compare Files and Folders and Merge Files
To select the files to compare, see “Select the Files or Folders to Compare” on page 6-6.
By default, XML files are compared using a text comparison. To compare XML files with a
hierarchical comparison instead, see “Compare XML Files” on page 6-25.
When you perform a text comparison, a new window opens and displays the two files side
by side. Symbols in between the two displayed files indicate how you can adjust the files
to make them match. For example, run this code to view a text comparison of the example
files lengthofline.m and lengthofline2.m.
file1 = fullfile(matlabroot,'help','techdoc','matlab_env',...
'examples','lengthofline.m')
file2 = fullfile(matlabroot,'help',...
'techdoc','matlab_env','examples','lengthofline2.m')
visdiff(file1,file2)
6-11
6 Managing Files in MATLAB
Explore Differences
The Comparison tool highlights the lines that have changed as described in this table.
6-12
Compare Files and Folders and Merge Files
The Comparison tool attempts to match lines and detects text that is added, deleted, or
changed. It does not do a simple line-by-line comparison. For example, in the text
comparison of lengthofline.m and lengthofline2.m, the tool determines that
lengthofline2.m has a line of code that does not exist in lengthofline.m and
highlights it (line 23) in blue. Also, notice that the tool 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. If it does, it displays this message:
When this occurs, the Comparison tool switches to a line-by-line comparison. In a line-by-
line comparison, the tool highlights the lines containing the end statement because in
performing this operation, it finds that the last line in one file does not match the last line
in the other file.
You further can explore and configure the results using several methods:
6-13
6 Managing Files in MATLAB
a message indicating the number of lines hidden. For example, if 10 lines are hidden,
the report displays 10 unmodified lines hidden.
• Change the display width — To increase or decrease the line lengths of the text files
in the comparison display, go to the View tab, and in the Display section, change the
Column Width. Resize the window if necessary.
• Save HTML Report — To save a copy of the comparison report as an HTML file, go to
the Comparison tab, and in the Comparison section, click Save As > HTML.
If a text file is lengthy, use the and buttons to step through the results one
difference at a time. Once the last difference has been reached, clicking the button
loops back to the first difference in the files. Similarly, if the first difference is selected
and the button is clicked, the Comparison tool loops to the last difference in the files.
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.
Tip You can only merge from left to right. If you want to merge into the left 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.
To merge a difference from the left file to the right file, select the difference in the report
and on the Comparison tab, click the Merge button. The Comparison tool
highlights merged lines in gray and displays a green merge arrow.
The merged file name at the top of the report indicates that the file contains unsaved
changes (filename.m*).
To revert the last merge operation, on the Comparison tab, click Undo. Click Redo to
reapply a merge. To revert all merges and start again, click Refresh.
6-14
Compare Files and Folders and Merge Files
To save your changes, click Save Merged File. To save to a different name, select Save
Merged File > Save Merged File As.
To view the files in the Editor, click a line number link 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 compare the latest version of a file with the Editor's backup copy, first open the file in
the Editor. Then, go to the Editor tab, click Compare , and 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 unsaved changes to the saved version, go to the Editor
tab, click Compare , and select Compare with Version on Disk.
You can compare and merge lines in two live code files using the Comparison tool. To
select the files to compare, see “Select the Files or Folders to Compare” on page 6-6.
When you perform a live code comparison, a new window opens and displays the two files
side by side. For example, suppose you have two files averageweight.mlx and
averageweight2.mlx with several differences. When you compare the two files, the
Comparison tool displays the resulting report.
6-15
6 Managing Files in MATLAB
Explore Differences
The Comparison tool displays the total number of differences in the bottom right corner of
the comparison report, and highlights the lines that do not match as described in this
table.
6-16
Compare Files and Folders and Merge Files
When comparing live code files, the Comparison tool detects differences in code, text, and
text formatting. The Comparison tool ignores output, even if the file contains saved
output. If the tool detects a difference within an equation, image, or control, the entire
item is highlighted.
The Comparison tool attempts to match lines and detects code and text that is added,
deleted, or changed. It does not do a simple line-by-line comparison. For example, in the
live code comparison of averageweight.mlx and averageweight2.mlx, the tool
determines that averageweight.mlx has two lines of code that do not exist in
averageweight2.mlx and highlights them (line 5 and line 7) in yellow. Also, notice that
the tool takes the additional lines into account and determines that the line containing the
disp statement in each file matches, even though the disp statement does not occur on
the same line number.
If a live code file is lengthy, use the Next and Previous buttons to step through
the results one difference at a time.
Merge Differences
When comparing live code files, you can merge changes from one file to the other.
Merging changes can be useful when resolving conflicts between different versions of
files. You only can merge from left to right. If you want to merge into the left file, click the
Swap Sides button before you start merging. Clicking the Swap Sides button
reverts any merges already made and creates a new comparison report for the original
files.
To begin merging, on the Comparison tab, click the Merge Mode button. Then, to
replace content from the right pane with content from the left pane, click the button
6-17
6 Managing Files in MATLAB
located next to the line you want to merge. You also can select a difference and in the
Merge tab, click the Replace Content button.
The right pane contains the merged result. An asterisk next to the merged file name in
the right pane (filename_modified.mlx*) indicates that the file contains unsaved
changes.
To undo a replacement, click the button between the modified lines or on the
Comparison tab. To revert all merges and start again, click the Refresh button. You
also can click the Refresh button to update the comparison report after making
changes to and saving the files in the Live Editor. Refreshing discards all merged
changes.
6-18
Compare Files and Folders and Merge Files
To save your changes and return to the comparison report, click the Save Result
button. To return to the comparison report without saving changes, click the Return
to Comparison button.
You can use the Comparison tool to compare two MAT-files. Compare two MAT-files to:
• Determine which variables are common to each file and which are unique.
• Identify differences between individual variables. For example, you can determine
which fields of a structure are different, or which elements of a array differ.
To select items to compare, see “Select the Files or Folders to Compare” on page 6-6.
When you perform a MAT-file comparison, a new window opens and displays the two files
side by side. For example, supposed you have two MAT-files, data1.mat and data2.mat.
When you compare the two files, the Comparison tool displays the resulting report.
6-19
6 Managing Files in MATLAB
Explore Differences
The Comparison tool report highlights changes in variables as described in this table.
6-20
Compare Files and Folders and Merge Files
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 that contain ignored
differences.
You can further explore the results in the report using several methods:
• Sort results — To sort the results by name, size, class, or difference summary, click
the corresponding column header. For example, click the Class column header to sort
by class type.
• Load variable — To load the contents of a variable into the Variable Editor, click the
name of that variable.
• Load MAT-file — To load one of the MAT-files into the workspace, click the
corresponding Load link at the bottom of the report.
• Save HTML report — To save a copy of the report as an HTML file, go to the
Comparison tab and click Save As > HTML.
For information about how to further configure the comparison report, see “Comparison
Report Tools and Options” on page 6-23.
Compare Variables
The variable comparison report displays differences in individual array elements or fields
of a structure. To investigate individual differences, double-click a highlighted row.
6-21
6 Managing Files in MATLAB
Merge Differences
When comparing MAT-files, you can merge changes from one file to the other. There are
no undo capabilities when merging MAT-files, so merge with caution.
To copy modified variables from one file to the other, on the Comparison tab, in the
Merge section, click the Merge button.
You can compare two binary files such as DLL files or MEX-files using the Comparison
tool. To select the files to compare, see “Select the Files or Folders to Compare” on page
6-6.
You also can perform a binary comparison on any two selected files, instead of the default
comparison. To compare any two files using a binary comparison, set the Comparison
type to Binary comparison. For more information, see “Compare Binary Files” on page
6-22.
6-22
Compare Files and Folders and Merge Files
When you perform a binary comparison, a new window opens and indicates whether the
two files are identical or different. If the files are different, click the Show Details link to
view the binary files and the byte offset of the first difference.
• Exchange the Left and Right Sides of the Report — To switch the left side file or
folder with the right side file or folder, go to the Comparison tab and click the
Swap Sides button.
• Refresh the Report to Show Updated File — After making changes to and saving
the files in the Editor, to update the results in the Comparison tool, go to the
After saving a color settings profile, you can select the profile in the Active
Settings list.
5 To restore the default settings, click Reset and then click Apply. Refresh the
comparison report.
6-23
6 Managing Files in MATLAB
Source Control
You can customize external source control tools to use the MATLAB Comparison tool for
comparing and merging files and folders. For more information, see “Customize External
Source Control to Use MATLAB for Diff and Merge”.
See Also
visdiff
Related Examples
• “Model Comparison” (Simulink)
6-24
Compare XML Files
In this section...
“Choose XML Files to Compare” on page 6-26
“Change Comparison Type” on page 6-27
“Navigate the XML Comparison Report” on page 6-27
“Save Comparison Log Files in a Zip File” on page 6-29
“Export Results to the Workspace” on page 6-29
You can use the Comparison tool to compare a pair of XML text files. The tool processes
the results into a report that you can use to explore the file differences. You can compare
XML files with a text comparison or a hierarchical XML comparison.
You can access the XML comparison tool from the Current Folder browser, the
Comparison Tool, or programmatically using the visdiff function.
The XML comparison compares the files using the “Chawathe” algorithm, as described in
this paper:
Change Detection in Hierarchically Structured Information, Sudarshan Chawathe, Anand
Rajaraman, and Jennifer Widom; SIGMOD Conference, Montreal, Canada, June 1996, pp.
493-504.
XML comparison reports display in the Comparison Tool. For more information about the
Comparison Tool, see “Compare Files and Folders and Merge Files” on page 6-6.
The XML comparison report shows a hierarchical view of the portions of the two XML
files that differ. The report does not show sections of the files that are identical.
If the files are identical, you see a message reporting there are no differences.
Note It might not be possible for the analysis to detect matches between previously
corresponding sections of files that have diverged too much.
6-25
6 Managing Files in MATLAB
Change detection in the Chawathe analysis is based on a scoring algorithm. Items match
if their Chawathe score is above a threshold. The implementation of Chawathe's
algorithm uses a comparison pattern that defines the thresholds.
• For two files in the same folder, select the files, right-click and select Compare
Selected Files/Folders.
• To compare files in different folders:
The XML comparison tool performs a Chawathe analysis on the files and displays a report
in the Comparison Tool. The file you right-click to open the XML comparison tool displays
on the right side of the report.
For more information about comparisons of other file types with the Comparison Tool,
such as text, MAT, or binary, see “Compare Files and Folders and Merge Files” on page 6-
6.
To compare files using the Comparison Tool, from the MATLAB toolstrip, in the File
section, select the Compare button. In the dialog box, select files to compare.
If the files you select to compare are XML files and you select an XML text
comparison, the XML comparison tool performs a Chawathe analysis of the XML files,
and generates a report.
6-26
Compare XML Files
To change comparison type, either create a new comparison from the Comparison Tool, or
use the Compare Against option from the Current Folder browser. You can change
comparison type in the Select Files or Folders for Comparison dialog box. Select XML
text comparison before clicking Compare.
To step through differences, use the Comparison tab on the toolstrip. To move to the
next or previous group of differences, on the Comparison tab, in the Navigate section,
click the arrow buttons to go to the previous or next difference.
6-27
6 Managing Files in MATLAB
Use the View tab controls on the toolstrip for the following functions:
Tip Right-click to expand or collapse the hierarchy within the selected tree node.
• Collapse All — Collapses all items in the tree to the most compact view possible.
Note It may not be possible for the analysis to detect matches between previously
corresponding sections of files that have diverged too much.
6-28
Compare XML Files
You can zip the temporary files (such as log files) created during XML comparisons, for
sharing or archiving. While the comparison report is open, enter:
xmlcomp.zipTempFiles('c:\work\myexportfolder')
The destination folder must exist. The output reports the zip file name:
To view the log file for the last comparison in the MATLAB Editor, enter:
xmlcomp.showLogFile
1 On the Comparison tab, in the Comparison section, select Save As > Save to
Workspace.
The xmlcomp.Edits object contains information about the XML comparison including
file names, filters applied, and hierarchical nodes that differ between the two XML files.
Edits = xmlcomp.compare(a.xml,b.xml)
6-29
6 Managing Files in MATLAB
6-30
See Also
See Also
Related Examples
• “Compare Files and Folders and Merge Files” on page 6-6
6-31
6 Managing Files in MATLAB
6-32
Manage Files and Folders
6-33
6 Managing Files in MATLAB
To open the Current Folder browser if it is not visible, go to the Home tab, and 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.
To add a quick access button to the toolbar, right-click the toolbar and select
Customize.... MATLAB opens the MATLAB Toolbar Preferences panel. In the Controls
section, select from the available options and click OK. For example, if you have MATLAB
6-34
See Also
Drive Connector installed, you can add a MATLAB Drive quick access button. To do so, in
the MATLAB Toolbar Preferences panel, select the Go to MATLAB Drive option and click
OK. MATLAB adds the button to the toolbar.
• Published — Stores the paths to your published program files and results reside,
publicly available to others on the web.
• Shared — Stores the paths to the files that others share with you.
To share a folder, in the Current Folder browser, right-click the item and select Share. To
transfer a file from MATLAB Online to the local system, select the file and on the Home
tab, select Download.
See Also
delete | edit | mkdir | movefile | open | recycle | rmdir
More About
• “Share and Restore Files in MATLAB Online” on page 10-2
• “Save and Load Workspace Variables” on page 5-16
• “Run Functions in the Editor”
• “Errors When Updating Folders on Search Path” on page 6-61
6-35
6 Managing Files in MATLAB
• 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-36
See Also
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
6-37
6 Managing Files in MATLAB
More About
• “What Is the MATLAB Search Path?” on page 6-48
• “MATLAB Startup Folder” on page 1-20
• “Toolbox Path Caching in MATLAB” on page 1-28
6-38
Current Folder Browser Preferences
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-39
6 Managing Files in MATLAB
Preference Usage
Path indication Control the appearance of folders and files that are inaccessible
to MATLAB, and whether to display tooltips describing their
status. MATLAB cannot access files if they are not on the
search path or, in some cases, if they are in a private folder.
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-40
Specify File Names
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-41
6 Managing Files in MATLAB
or
MATLAB always accepts absolute path names (also called full path names), such as I:/
Documents/My_Files or /users/myuserid/Homework/myfile.m. 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-42
Specify File Names
open database/set
• Locate method files. For example, to check if a plot method exists for the time series
object, type:
exist timeseries/plot
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.
6-43
6 Managing Files in MATLAB
When multiple files have the same name, MATLAB follows precedence rules to determine
which to call. For more information, see “Function Precedence Order”.
• 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-48
6-44
Create and Extract from Zip Archives
• To create an empty zip file, right-click white space, and then select New > 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-45
6 Managing Files in MATLAB
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.
MATLAB extracts the file and saves it to the folder where you dragged or pasted it.
6-46
See Also
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
• “Compare Files and Folders and Merge Files” on page 6-6
6-47
6 Managing Files in MATLAB
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-52.
6-48
What Is the MATLAB Search Path?
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. Files and folders not on the path are dimmed. To ensure that the Current Folder
browser is set to indicate whether a file or folder in on the search path, right-click any file
or folder, and select the Indicate Files Not on Path option.
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-49
6 Managing Files in MATLAB
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-52.
6-50
See Also
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.
In MATLAB Online, all changes to the search path are automatically saved.
See Also
userpath
More About
• “Add Folders to the MATLAB Search Path at Startup” on page 6-56
• “Change Folders on the Search Path” on page 6-52
6-51
6 Managing Files in MATLAB
1 On the Home tab, in the Environment section, click Set Path. The Set Path dialog
box appears.
6-52
Change Folders on the Search Path
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.
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-48
6-53
6 Managing Files in MATLAB
• 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-54
Use Search Path with Different MATLAB Installations
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-26
6-55
6 Managing Files in MATLAB
addpath /home/username/mytools
For more information on creating a startup.m file with addpath statements, see
“Startup Options in MATLAB Startup File” on page 1-26.
Windows
To set the MATLABPATH environment variable in Windows, from the Windows Control
Panel, go to System and select Advanced system settings. Click the Environment
Variables... button. Click New... or Edit... to create or edit the MATLABPATH environment
variable. In the dialog box that appears, set the variable name to MATLABPATH and the
variable value to a semicolon-separated list of folders you want to add to the search path.
For example, to add two folders, c:\matlab_files\myfolder1 and c:
\matlab_files\myfolder2, to the MATLABPATH environment variable, enter c:
\matlab_files\myfolder1;c:\matlab_files\myfolder2 as the variable value.
Click OK to set the variable and exit the dialog box. Restart MATLAB for the new settings
to take effect.
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-56
See Also
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.
See Also
More About
• “What Is the MATLAB Search Path?” on page 6-48
• “Change Folders on the Search Path” on page 6-52
6-57
6 Managing Files in MATLAB
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-58
Path Unsuccessfully Set at Startup
• 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:
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-52. 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.
6-59
6 Managing Files in MATLAB
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
savepath('path_to_your_startup_folder/pathdef.m')
After correcting problems with the search path, make any changes to run your files. For
example, add the userpath folder or other folders to the search path.
6-60
Errors When Updating Folders on Search Path
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-61
6 Managing Files in MATLAB
If your file system updates folder timestamps when files are added to folders, you can set
your system remote path policy to detect changes by testing the timestamps of folders. To
do so, include these commands in a startup.m file. For more information on creating a
startup.m file, see “Startup Options in MATLAB Startup File” on page 1-26.
system_dependent('RemotePathPolicy', 'TimecheckDir');
rehash path;
You might notice a performance degradation due to the time required to check the
timestamps.
6-62
Troubleshoot Invalid or Unresponsive Windows Change Notification Handles
If your file system does not update folder timestamps (such as an NT file system), you can
set your system remote path policy to detect changes by rereading the affected folders at
frequent intervals. To do so, include these commands in a startup.m file.
system_dependent('RemotePathPolicy', 'Reload');
rehash path;
You might notice a significant performance degradation due to the time required to
reread the folders.
system_dependent('RemotePathPolicy', 'Status');
In some cases, detecting new files or changed files in folders affected by the invalid or
unresponsive change notification handles is not necessary. If detecting changes is not
necessary, to provide maximum performance, you can disable your system remote path
policy. To do so, include these commands in a startup.m file.
system_dependent('RemotePathPolicy', 'None');
rehash path;
• Show warning messages for all invalid or unresponsive change notification handles.
system_dependent('DirChangeHandleWarn', 'Always');
6-63
6 Managing Files in MATLAB
• Only show the first warning message about invalid or unresponsive change notification
handles.
system_dependent('DirChangeHandleWarn', 'Once');
• Never show warning messages about invalid or unresponsive change notification
handles.
system_dependent('DirChangeHandleWarn', 'Never');
system_dependent('DirChangeHandleWarn', 'Status');
See Also
addpath | rehash
More About
• “What Is the MATLAB Search Path?” on page 6-48
• “Startup Options in MATLAB Startup File” on page 1-26
6-64
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-4
“Editor/Debugger Tab Preferences” on page 7-5
“Editor/Debugger Language Preferences” on page 7-6
“Editor/Debugger Code Folding Preferences” on page 7-9
“Editor/Debugger Backup Files Preferences” on page 7-10
“Editor/Debugger Autoformatting Preferences” on page 7-11
“Editor/Debugger Autocoding Preferences” on page 7-13
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.
7-2
Editor/Debugger Preferences
Preference Usage
Editor Select which editor you want the MATLAB
desktop to use when you edit a file:
• MATLAB Editor
• Text editor
7-3
7 Editor Preferences
Preference Usage
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.
Debugging in the Live Editor Select Only show Step in button for user-
defined functions to have the Live Editor only
step into user-defined functions and scripts. To
have the Live Editor step into MathWorks
functions as well, clear the option.
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. This preference applies in both the
Editor and Live Editor.
7-4
Editor/Debugger Preferences
Preference Usage
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.
Option Usage
Tab size Specify the amount of space inserted when you
press the Tab key.
7-5
7 Editor Preferences
Option Usage
Tab key inserts spaces Select to insert a series of spaces when you
press the Tab key. Otherwise, a tab acts as one
space whose length is equal to the Tab size.
Emacs-style Tab key smart indenting Specifies an indenting style similar to the style
that the Emacs editor uses.
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.
Preference Usage
Language Select the language for which you want to set
preferences.
7-6
Editor/Debugger Preferences
Preference Usage
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-7
7 Editor Preferences
Preference Usage
Comment formatting In the Maximum column width field, enter the
maximum number of characters you want to allow in a
MATLAB Language only line of comments, and then select where you want
counting to begin.
Consider selecting:
7-8
Editor/Debugger Preferences
Preference Usage
Indenting Select Apply smart indenting while typing to
automatically:
7-9
7 Editor Preferences
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.
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.
7-10
Editor/Debugger Preferences
Preference Usage
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-11
7 Editor Preferences
On the Home tab, in the Environment section, click Preferences. Select Editor/
Debugger > Autoformatting, and then adjust preference options as described in this
table.
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 (_).
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 heading 1
style headings by entering %%text and then
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).
7-12
Editor/Debugger Preferences
Preference Usage
Select (TM), (SM), (R), and (C) for
trademark, service mark, and copyright
symbols to enable inserting trademark and
copyright symbols (™, ℠, ®, and ©) using the
format (TM), (SM), (R), and (C).
Text Style Select #text for title to enable inserting titles
using the format #text.
Select ##text, ###text, or ####text for
heading to enable inserting headings using the
format ##text for heading 1, ###text for
heading 2, or ####text for heading 3.
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.
For more information about autoformatting in the Live Editor, see “Autoformatting”.
On the Home tab, in the Environment section, click Preferences. Select Editor/
Debugger > Autocoding, and then adjust preference options as described in this table.
Preference Usage
Enable autocoding in Live Editor Select to enable autocoding options in the Live
Editor. Once enabled, options can be enabled or
disabled individually.
7-13
7 Editor Preferences
Preference Usage
Autocomplete parentheses Select Parentheses ( ) to enable autocompletion
of parentheses.
Select Curly braces { } to enable
autocompletion of curly braces.
Select Square brackets [ ] to enable
autocompletion of square brackets.
Autocomplete quotes Select Single quotes (' ') to enable
autocompletion of single quotes.
Select Double quotes (" ") to enable
autocompletion of double quotes.
Autocomplete when splitting Select Comments (%) to enable autocompletion
of comments when split across two lines. For
example, pressing Enter with your cursor after
the period in the comment
7-14
Editor/Debugger Preferences
Preference Usage
Select Strings (" ") to enable autocompletion of
strings when split across two lines. For example,
pressing Enter with your cursor after the word
long in the string
exist("exceptionally_long_file_name.txt")
exist("exceptionally_long" + ...
"_file_name.txt")
Autocomplete block endings Select Control flow statements (if, for, etc.)
to enable autocompletion of control flow
statements. To autocomplete a statement, enter
the statement and press Enter. For a list of
control flow statements, see “Control Flow”.
Select Function and class definitions to
enable autocompletion of functions and class
definitions. To autocomplete a definition, enter
either function or class and press Enter.
7-15
7 Editor Preferences
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-16
Code Analyzer Preferences
Option Usage
Active Settings Select the set of message settings to use. Click
the down arrow to select or browse to a
previously saved settings file.
Actions button Click to open a menu that enables you to select:
Note If you do not have the MATLAB Compiler™ installed, the Code Analyzer
preferences pane does not display the MATLAB Compiler (deployment) messages
category.
7-17
7 Editor Preferences
7-18
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
Messages in Category, and then make it difficult for others to use
click the category you want. your code.
7-19
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-20
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 section, click
Find add-ons by browsing through available categories 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 adjusting your desktop environment.
8-2
See Also
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 an add-on manually, double-click the add-on installation file in the MATLAB
Current Folder browser. An installer opens to guide you through the installation process.
Valid installation files include .mltbx files (toolboxes), .mlappinstall files (apps),
and .mlpkginstall files (hardware support packages).
For some add-ons, you also can download the add-on from the Add-On Explorer without
installing it. Downloading an add-on without installing it is useful if you want to install the
add-on on a system without an internet connection. To download the add-on, select
Install > Download Only. Then install the add-on manually by double-clicking the
downloaded file in the MATLAB Current Folder browser
See Also
Related Examples
• “Manage Your Add-Ons” on page 8-4
8-3
8 Add-Ons
In this section...
“Run Apps” on page 8-5
“Default Add-Ons Installation Folder” on page 8-5
You can view and manage installed add-ons using the Add-On Manager. To open the Add-
On Manager, go to the Home tab and select Add-Ons > Manage 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.
To manage an individual add-on, click the options button to the right of the add-on and
select from the available options. Options include:
8-4
Manage Your Add-Ons
Run Apps
To run an app after you install it, go to the Apps tab and expand the apps gallery by
clicking the down arrow on 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.
8-5
8 Add-Ons
In MATLAB Online, all supported MathWorks products and support packages are pre-
installed and reinstalling them is not supported. The default installation folder for all
other add-ons is /MATLAB Add-Ons. Changing the default installation folder or
customizing installed add-ons is not supported.
See Also
Related Examples
• “Get Add-Ons” on page 8-2
8-6
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
See Also
• 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.
See Also
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-9
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.
9-5
9 Internationalization
System Locale
1 From the Control Panel, select Clock, Language, and Region > Region.
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.
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
See Also
External Websites
• Why does MATLAB fail to load my preferred language on macOS Sierra?
9-8
Set Locale on Linux 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.
See Also
More About
• “Numbers Display Period for Decimal Point” on page 9-13
9-9
9 Internationalization
MATLAB ignores the LANG environment variable and the Terminal application locale
setting.
See Also
Related Examples
• “Set Locale on Mac Platforms” on page 9-7
9-10
Characters Incorrectly Displayed on Windows Systems
See Also
Related Examples
• “Set Locale on Windows Platforms” on page 9-5
9-11
9 Internationalization
cd(matlabroot)
f = dir('license_agreement.txt')
f =
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-12
Numbers Display Period for Decimal Point
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.
See Also
More About
• Symbol Reference: Comma
9-13
9 Internationalization
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.
See Also
More About
• “Locale Settings for MATLAB Process” on page 9-2
9-14
Script Compatibility
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-15
9 Internationalization
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.
See Also
More About
• “General Preferences” on page 2-42
9-16
X Servers and International Keyboard Layouts
Suppose you are using a Linux based computer with a German keyboard. Without the
XKEYBOARD extension, Simulink uses the default layout, which is English, and can
therefore produce incorrect characters. MATLAB correctly recognizes the keyboard as
German.
If you encounter this issue, try enabling the XKEYBOARD extension, or use an X server that
supports this extension.
9-17
10
MATLAB Online
10 MATLAB Online
1 In your home folder, create a folder to contain the files you want to share.
4 Click edit. Enter the email addresses or user IDs of the people with whom you want
to share the files in that folder. When sharing with more than one person, enter each
address or ID on a new line, or separate them with a comma, space, or semicolon.
10-2
Share and Restore Files in MATLAB Online
Note MATLAB only recognizes the email addresses and user IDs of people who have
previously logged in to MATLAB Online.
5 Click OK.
To stop sharing files with others, open the Sharing dialog box and delete the IDs of the
people who should not view the files. Alternatively, delete the files or the folder.
When someone shares a folder with you, the folder appears within the Shared subfolder
of your home folder, as shown here.
10-3
10 MATLAB Online
For example, suppose that your user ID is youruserid, and a colleague whose user ID is
yourprofessor shared with you a folder named Engineering-101. The path to the
folder is
/users/youruserid/Shared/yourprofessor/Engineering-101
Although you cannot change the contents of the folder, you can perform any of these
operations:
Note Sometimes files shared with you have the same names as files you created. For
information on how MATLAB deals with multiple files that have the same name, see “Files
and Folders that MATLAB Accesses” on page 6-36.
Browse for the file you want by selecting from the list, or by clicking Older or Newer.
When you find the file, click Restore as Latest. MATLAB adds the restored file to the top
of your history with a new timestamp and version number.
10-4