Skip to Main Content Skip to Search
Product Documentation

Shell Escape Functions

It is sometimes useful to access your own C or Fortran programs using shell escape functions. Shell escape functions use the shell escape command ! to make external stand-alone programs act like new MATLAB functions. A shell escape function

  1. Saves the appropriate variables on disk.

  2. Runs an external program (which reads the data file, processes the data, and writes the results back out to disk).

  3. Loads the processed file back into the workspace.

For example, look at the code for garfield.m, below. This function uses an external function, gareqn, to find the solution to Garfield's equation.

function y = garfield(a,b,q,r)
save gardata a b q r
!gareqn
load gardata

This file

  1. Saves the input arguments a, b, q, and r to a MAT-file in the workspace using the save command.

  2. Uses the shell escape operator to access a C or Fortran program called gareqn that uses the workspace variables to perform its computation. gareqn writes its results to the gardata MAT-file.

  3. Loads the gardata MAT-file described in Custom Applications to Read and Write MAT-Files to obtain the results.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS