# MATLAB - Fortran interface

**URL:** <https://fortran-lang.discourse.group/t/matlab-fortran-interface/1322>\
**Category:** Help\
**Created:** [May 29, 2021, 4:15pm UTC](https://fortran-lang.discourse.group/t/matlab-fortran-interface/1322 "2021-05-29T16:15:04Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [May 31, 2021, 1:49am UTC](https://fortran-lang.discourse.group/t/matlab-fortran-interface/1322/10 "2021-05-31T01:49:25Z")

</div>

Just for comparison, here is a C MEX file for the same callback:

```auto
// vanderpol.c

#include "mex.h"
#include "matrix.h"

#include "vanderpol_mod.h"

void
mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{

    // Value of independent variable
    const double *t = mxGetDoubles(prhs[0]);

    // Get number of rows in column vector y
    const int m = mxGetM(prhs[1]);
    // Get pointer to dependent variables
    const double *y = mxGetDoubles(prhs[1]);

    // Create output buffer
    plhs[0] = mxCreateDoubleMatrix(m,1,mxREAL);
    double *dydt = mxGetDoubles(plhs[0]);

    f_vanderpol(&m,t,y,dydt);

}

```

To compile this function use the command

```nohighlight
mex -R2018a vanderpol.c vanderpol_mod.o

```

---

_[View the full topic](https://fortran-lang.discourse.group/t/matlab-fortran-interface/1322)._
