Specify Startup Options - MATLAB & Simulink (original) (raw)
Startup Options from Operating System Prompt
Startup options instruct MATLAB® to perform certain operations when you start the program. Startup options also are called command flags or command-line switches. When you start at the operating system prompt, specify the options as arguments to thematlab
command. For example, the following starts MATLAB without the desktop.
On Windows® platforms, you can precede a startup option with either a hyphen (-
) or a slash (/
). For example,-nodesktop
and /nodesktop
are equivalent.
Startup Options in Shortcut on Windows Systems
You can add selected startup options to the target path for your shortcut on the Windows platform for MATLAB.
To use startup options for the MATLAB shortcut icon, follow these steps:
- Right-click the shortcut icon for MATLAB
and select from the context menu. The Properties dialog box for MATLAB opens to the Shortcut pane.
- In the Target field, after the target path for
"matlab.exe"
, add the startup option, and click OK.
This example runs the MATLABresults
script or function after startup, whereresults.m
is in the startup folder or on the MATLAB search path. The text in the Target field is similar to the following:
"C:\Program Files\MATLAB\R2016b\bin\matlab.exe" -r "results"
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 fileresults
:
"... matlab.exe" -r "format('short');results"
Separate multiple options with spaces. This example starts MATLAB without the desktop, and then runs the MATLAB code fileresults
:
"... matlab.exe" -nodesktop -r "results"
Startup Options in MATLAB Startup File
The startup.m
file is a file you create to specify startup options. Create the startup.m
file in a folder on the MATLAB search path. Use startup.m
to modify the default search path, predefine variables in your workspace, or define defaults for graphics objects. For example, the following statement adds the user-defined folder/home/myname/mytools
to the search path.
addpath /home/myname/mytools
To change the current folder on startup to mytools
, set the value, located in theGeneral Settings options in the Settings window:
At startup, MATLAB automatically executes the matlabrc.m
file andstartup.m
, if it exists on the MATLAB search path. The file matlabrc.m
, which is in the_matlabroot
_/toolbox/local
folder, is reserved for use by MathWorks® and by system administrators on multiuser systems. To locate thestartup.m
file, type:
If MATLAB finds a startup.m
file, then it displays the path to the file.
Note
MATLAB executes any file on the search path named startup
that has an executable file extension. Examples of an executable file extension are .m
,.mlx
, and .mlapp
.
Passing Perl Variables on Startup
You can pass Perl variables to MATLAB on startup by using the -r
option of thematlab
function. For example, assume a MATLAB function test
that takes one input variable:
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 argument10
.
- Create a Perl script such as
#!/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 inmatlab (Windows), matlab (macOS), or matlab (Linux).
Startup and Calling Java Software from MATLAB
When MATLAB starts, it constructs the class path for Java® software using javaclasspath.txt
andjavalibrarypath.txt
files. For more information, see Java Class Path andLocate Native Method Libraries.
For information about memory allocation for Java objects, see Java Heap Memory Settings.
See Also
matlab (Windows) | matlab (macOS) | matlab (Linux)