Академический Документы
Профессиональный Документы
Культура Документы
Documentation
CONTENTS
Run External Commands, Scripts, and Programs
The exclamation point character (!) sometimes called bang, is a shell escape. The character indicates that the rest of the input line is a command to the
operating system. Use it to invoke utilities or call other executable programs without quitting MATLAB®. To use the exclamation point in a factorial expression,
call the factorial function.
For example, the following code opens the vi editor for a file named yearlystats.m on a UNIX® platform.
!vi yearlystats.m
After the external program completes or you quit the program, the operating system returns control to MATLAB. Add & to the end of the line, such as
!dir &
on Windows® platforms to display the output in a separate window or to run the application in background mode. For example:
!excel.exe &
opens Microsoft® Excel® software and returns control to the command prompt so you can continue running MATLAB language statements.
Restrictions maintained within the operating system determine the maximum length of the argument list you can provide as input to the bang (!) command.
For details about running external programs that return results and status, see the unix, dos, and system functions.
Note
To execute operating system commands with specific environment variables, include all commands to the operating system within the system call.
Separate the commands using & (ampersand) for DOS, and ; (semicolon) for UNIX platforms. This applies to the MATLAB ! (bang), dos, unix, and
system functions. Another approach is to set environment variables before starting MATLAB.
On Mac platforms, you cannot run AppleScript (from Apple) directly from MATLAB. To run AppleScript commands, call the Apple macOS osascript function
using the MATLAB unix or ! (bang) functions.
getenv('PATH')
You can make modifications to the system path that persist for the current MATLAB session or across subsequent MATLAB sessions, as described in the
sections that follow.
If you restart MATLAB, the folder is no longer on the system path visible to MATLAB.
Modify System Path Across MATLAB Sessions Within Current Shell Session
To add a folder to the system path from the shell:
1. Stop MATLAB.
2. Depending on the shell you are using, type one of the following at the system command prompt, where myfolder is the folder that contains the program
you want to run:
converted by Web2PDFConvert.com
• If you are using bash or a related shell, type:
export PATH="$PATH:myfolder"
3. Start MATLAB.
4. In the MATLAB Command Window, type:
!echo $PATH
If you restart MATLAB within the current shell session, the folder remains on the system path visible to MATLAB. However, if you restart the shell session,
and then restart MATLAB, the folder is no longer on the system path visible to MATLAB.
See Also
dos | factorial | system | unix | winopen
Trial Software
Product Updates
MATLAB Documentation
Other Documentation
Support
converted by Web2PDFConvert.com
The Manager's Guide to Solving the Big Data Conundrum
Download white paper
Explore Products
MATLAB
Simulink
Student Software
Hardware Support
File Exchange
Try or Buy
Downloads
Trial Software
Contact Sales
Pricing and Licensing
Learn to Use
Documentation
Tutorials
Examples
Videos and Webinars
Training
Get Support
Installation Help
Answers
Consulting
Application Status
License Center
converted by Web2PDFConvert.com
About MathWorks
Careers
Newsroom
Social Mission
About MathWorks
MathWorks
Accelerating the pace of engineering and science
MathWorks is the leading developer of mathematical computing software for engineers and scientists.
Discover...
United States
Patents
Trademarks
Privacy Policy
Preventing Piracy
© 1994-2017 The MathWorks, Inc.
converted by Web2PDFConvert.com