User`s guide

5 Controlling Code Generation
5-42
We recommend tha t you include this header file when defining the function.
This function could be implemented in this C file,
measure.c,usingthe
measure_from_device() function.
#include "matlab.h"
#include "collect_external.h"
#include <math.h>
extern double measure_from_device(void);
mxArray *Mcollect_collect_one( int nargout_ )
{
return( mlfScalar( measure_from_device() ));
}
double measure_from_device(void)
{
static double t = 0.0;
t = t + 0.05;
return sin(t);
}
In general, the Compiler will use the same interface for this function as it
would generate. To generate the C code and header file, use
mcc -c collect.m
By examining the Compiler-generated C code, you should easily be able to
determine how to implement this interface. To compile
collect.m to a
MEX-file, use
mcc -x collect.m measure.c
Using Pragmas
Using feval
In stand-alone C and C++ modes, the pragma
%#function <function_name-list>
informs the MATLAB Compiler that the specified function(s) will be called
through an
feval call or through a MATLAB function that accepts a function
to
feval as an argument or contains an eval string or Handle Graphics