title: Is there a way to use MATLAB function handles in MEX files without the mexCallMATLAB function
body: <p>I'm currently writing a MEX file in C to speed up MATLAB code that heavily relies on function handles. Unfortunately, my MEX file runs slower than it should because I have to to use <code>mexCallMATLAB</code>  to evaluate the handles in MATLAB (as described <a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/274319" rel="nofollow">here</a>). </p>
  
  <p>Most of the function handles are simple inline functions that take uniform random numbers and generate random variables. A typical example is:</p>
  
  <pre><code>f = @(u) exp(norminv(u)) 
  </code></pre>
  
  <p>Even as the function handles use built-in MATLAB functions, my code has to allow users to use their own function handles, which prevents me from hard coding the functions into a MEX file. </p>
  
  <p>Ideally I would like to provide the MEX file with a way to evaluate this function handle without having to use the <code>mexCallMATLAB</code> function everytime. Does anyone have any idea on how such a thing can be done? I'm open to any suggestions you may have. </p>