Shell Escape Function Example - MATLAB & Simulink (original) (raw)
Main Content
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.
For example, the following function, garfield.m
, 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 function:
- Saves the input arguments
a
,b
,q
, andr
to a MAT-file in the workspace using thesave
command. - 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 thegardata
MAT-file. - Loads the
gardata
MAT-file to obtain the results.