MATLAB_OS
Examples of MATLAB calling the Computer Operating System (OS)


MATLAB_OS is a directory of MATLAB programs which illustrate how to issue a command to the computer operating system (OS), and collect the results. This is one way that, for instance, MATLAB can continue running, but start up an external executable program that carries out some useful task. For example, MATLAB might create a file, the program might modify it, and MATLAB might use the results.

The call to the operating system has the form

[ status, string ] = system ( command )
where

For example, while running MATLAB, a UNIX user might issue the command

[ status, string ] = system ( 'who' );
and a Microsoft Windows user might issue the command
[ status, string ] = system ( 'dir' );

On a Unix system, the user may use the unix command, and on a PC running Windows, the dos command may be issued. In the case of a dos command, it may be useful to terminate the quoted string with an ampersand, in which case the console will open in a separate window.

If the status and printed output of the system command are of no interest, it is possible to run the command simply using the exclamation mark followed by the command. It is not necessary in this case to put quotes around the command.

For example, while running MATLAB, a UNIX user might issue the command

! who
and a Microsoft Windows user might issue the command
! dir

Since a user's compiled program can be treated as another system command, a MATLAB user might want to run the program a.out while pausing (but not terminating) the MATLAB session. In this way, the a.out program might be able to read files that MATLAB produced, and produce new files that the MATLAB user will need. If the program a.out is in the right place, the command might be as simple as

[ status, string ] = system ( 'a.out' );
or, perhaps
! a.out
or, if input and output files need to be named:
[ status, string ] = system ( 'a.out < input > output' );
or, perhaps
! a.out < input > output

Related Data and Programs:

F90_CALLS_MATLAB, FORTRAN90 programs which call MATLAB to carry out an auxillary calculation.

MATLAB, MATLAB programs which illustrate some common operations.

MATLAB_CALLS_C, MATLAB programs which call a C function using the MEX facility.

MATLAB_COMMANDLINE, MATLAB programs which illustrate how MATLAB can be run from the UNIX command line, that is, not with the usual MATLAB command window.

MATLAB_CALLS_F77, MATLAB programs which call a FORTRAN77 function using the MEX facility.

MATLAB_MOVIES, MATLAB programs which generate animations.

Reference:

Examples:

BANG_WHO is an example in which the "bang" command (exclamation mark) is used to invoke the (Unix) system command who.

DOS_DIR is an example in which the dos command is used to invoke the (MS/DOS) system command dir.

SYSTEM_MORE is an example in which the system command is used to invoke the (Unix or MS/DOS) system command more.

UNIX_HEAD is an example in which the unix command is used to invoke the (Unix) system command head.

You can go up one level to the MATLAB source codes.


Last revised on 19 July 2006.