## Matlab Fortran MEX selftest

These commands are all from within Matlab. They demonstrate that Matlab (or GNU Octave) MEX Fortran compiler wrapper is working on your system.

using homepath.m, copy over an example Fortran program.

`copyfile(fullfile(matlabroot,'extern','examples','refbook','timestwo.F'), homepath) copyfile(fullfile(matlabroot,'extern','include','fintrf.h'), homepath)`

- in Matlab or Octave:

`mex timestwo.F`

Building with ‘gfortran’. MEX completed successfully

- in Matlab or Octave:
in Matlab or Octave:

`timestwo(3)`

ans = 6.0

## Matlab MEX Fortran issues

`mex -setup -v FORTRAN mex.getCompilerConfigurations('FORTRAN')`

If you get error

… Looking for folder ‘libgfortranbegin.a’ …No. Did not find installed compiler ‘gfortran’. Error using mex No supported compiler or SDK was found. For options, visit https://www.mathworks.com/support/compilers/current_release/.

For Windows, even through R2019a, MinGW Gfortran is not supported. The solution for Matlab and Fortran on Windows is to use Intel Fortran compiler, which is not free.

Consider using GNU Octave and Gfortran on Windows and Mac. Gfortran and Matlab MEX are fine on Linux.