Sunteți pe pagina 1din 2

How do I call MATLAB from the DOS prompt?

- MATLAB Answers - MATLAB Central

1 of 2

http://www.mathworks.com/matlabcentral/answers/102082-how-do-i-call-matlab-from-the-dos-prompt

Related Content

How do I call MATLAB from the DOS prompt?

MATLAB Answers

Asked by MathWorks Support Teamon 1 Oct 2013


Latest activity Answered by jerryon 31 Mar 2014
Accepted Answer by MathWorks Support Team
0

1,464 views (last 30 days)

I would like to call MATLAB from the DOS prompt without opening it, and have it return a specific output file.

How can I call MATLAB from a


Windows command prompt or a Linux
Shell and not return control until
MATLAB has finished executing?
1 Answer

0 Comments

Why does only one line in my batch file


get executed when working with
MATLAB 7.4 (R2007a)?
1 Answer

Tags

Products

mode background pc redirect mfile startup scheduler schedule


autoexec bat

MATLAB

How can I redirect the Command


Window output to stdout and stderr
when running MATLAB 7.8 (R2009a) in
batch mode?
1 Answer

Entire Website

2 Answers

Run External Commands, Scripts, and


Programs
Answer by MathWorks Support Teamon 1 Oct 2013
Accepted answer

1
Link

Documentation

To start MATLAB from a DOS window running inside Windows, do the following:

Build Models from a Windows


Command Prompt Window

1. Open a DOS prompt

Examples

2. Change directories to $MATLABROOT\bin

Standalone Real-Time Application Boot


Configuration

(where $MATLABROOT is the MATLAB root directory on your machine, as returned by typing
Documentation

matlabroot

at the MATLAB Command Prompt.)


3. Type "matlab"
You can also create your own batch file in the $MATLABROOT\bin directory
NOTE: If you have other commands that follow the call to MATLAB in your batch file, use matlab.exe rather than
matlab.bat. If you call on matlab.bat, subsequent commands in the batch file will not get executed.

MATLAB and Simulink resources


for Arduino, LEGO, and
Raspberry Pi
Learn more

To do so, use the following instructions:


1. Create a file called mat.bat and place the following line into it:

win $MATLABROOT\bin\matlab.exe

Discover what MATLAB


can do for your career.
Opportunities for recent
engineering grads.

2. Insert $MATLABROOT\bin into the path in the autoexec.bat file.

Apply Today
(where $MATLABROOT is the MATLAB root directory on your machine, as returned by typing

matlabroot

at the MATLAB Command Prompt.)


Now you can type mat at the dos prompt and Windows will come up with MATLAB.

MATLAB Academy
New to MATLAB?

You can run MATLAB from the DOS prompt and save the session to an output file by doing the following:

Learn MATLAB today!


matlab -r matlab_filename_here -logfile c:\temp\logfile

Depending on the directory you are in, you may need to specify the path to the executable. The MATLAB file you
want to run must be on your path or in the directory. This MATLAB file can be a function that takes arguments or a
script.
When running a script 'myfile.m', use the following command:

matlab -r myfile

When calling a function 'myfile.m' which accepts two arguments:

matlab -r myfile(arg1,arg2)

To pass numeric values into 'myfile.m' simply replace 'arg1' and 'arg2' with numeric values. To pass string or
character values into 'myfile.m' replace 'arg1' and 'arg2' with the string or character values surrounded in single
quotes. For exampl to pass the string values 'hello' and 'world' into 'myfile.m' use the following command:

matlab -r myfile('hello','world')

Note that the logfile will contain everything that was displayed to the Command Window while the MATLAB file was
running. If you want to generate any print files you need to do this in the MATLAB file. You can combine this
example with the above one to create a batch file that takes input files and creates output files.
In addition, this will call up an additional instance of the MATLAB command window. If you wish this to exit after the
computation is complete, you will need to add the command 'exit' to the end of your MATLAB file. You can
suppress the splash screen by adding the -nosplash flag to the above command so it looks like the following:

matlab -nosplash -r mfile -logfile c:\temp\logfile

5/24/2016 11:03 PM

How do I call MATLAB from the DOS prompt? - MATLAB Answers - MATLAB Central

2 of 2

http://www.mathworks.com/matlabcentral/answers/102082-how-do-i-call-matlab-from-the-dos-prompt

Although you cannot prevent MATLAB from creating a window when starting on Windows systems, you can force
the window to be hidden, by using the start command with the -nodesktop and -minimize options together:

start matlab -nosplash -nodesktop -minimize -r matlab_filename_here -logfile c:\temp\logfile

If you would like to call multiple MATLAB functions using the -r switch you could write a single function which will call
each of the other MATLAB functions in the desired order.
Note: Batch files can be called from Windows scheduler in order to run MATLAB commands at specific times. May
not work for UNC pathnames.

0 Comments

Answer by jerryon 31 Mar 2014

thank you very much, this is extremely helpful for me!

0
Link

0 Comments

1994-2016 The MathWorks, Inc.

5/24/2016 11:03 PM

S-ar putea să vă placă și