Programming |
Operating System Compatibility
This section covers the following topics:
Executing O/S Commands from MATLAB
To execute a command from your operating system prompt without having to exit MATLAB, precede the command with the MATLAB !
operator.
On Windows, you can add an ampersand (&)
to the end of the line to make the output appear in a separate window.
For more information: See Running External Programs in the MATLAB Desktop Tools and Development Environment documentation, and the system
and dos
function reference pages.
Searching Text with grep
grep
is a powerful tool for performing text searches in files on UNIX systems. To grep
from within MATLAB, precede the command with an exclamation point (!grep
).
For example, to search for the word warning
, ignoring case, in all M-files of the current directory, you would use
Constructing Paths and Filenames
Use the fullfile
function to construct path names and filenames rather than entering them as strings into your programs. In this way, you always get the correct path specification, regardless of which operating system you are using at the time.
Finding the MATLAB Root Directory
The matlabroot
function returns the location of the MATLAB installation on your system. Use matlabroot
to create a path to MATLAB and toolbox directories that does not depend on a specific platform or MATLAB version.
The following example uses matlabroot
with fullfile
to return a platform-independent path to the general
toolbox directory:
Temporary Directories and Filenames
If you need to locate the directory on your system that has been designated to hold temporary files, use the tempdir
function. tempdir
returns a string that specifies the path to this directory.
To create a new file in this directory, use the tempname
function. tempname
returns a string that specifies the path to the temporary file directory, plus a unique filename.
For example, to store some data in a temporary file, you might issue the following command first.
Starting MATLAB | Demos |
© 1994-2005 The MathWorks, Inc.