Matlab Fortran MEX selftest

Here is a quick test to help ensure your system is properly setup to compile Fortran MEX Matlab programs.

  1. in Matlab:

     copyfile(fullfile(matlabroot,'extern','examples','refbook','timestwo.F'),'~') 
     copyfile(fullfile(matlabroot,'extern','include','fintrf.h'),'~') 
    
  2. in Matlab or Octave:

     mex timestwo.F
    

yields:

Building with ‘gfortran’. MEX completed successfully

Finally, in Matlab or Octave:

timestwo(3)

ans = 6.0

Matlab MEX Fortran issues

Try

mex -setup -v 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 http://www.mathworks.com/support/compilers/current_release/.

Then select the Gfortran version suitable for your Matlab release.

Leave a Comment