Code covered by the BSD License  

Highlights from

3.6 | 6 ratings Rate this file 12 Downloads (last 30 days) File Size: 156 KB File ID: #4443
image thumbnail



Ben Barrowes (view profile)


03 Feb 2004 (Updated )

matlab2fmex.m is a small translator which aims to convert numerical M-files to Fortran90 mex.

Editor's Notes:

This author's upload was somehow corrupted. We fixed this on March 29, 2006. At that time, we also converted it from a GZ file a ZIP file for better cross platform portability.

| Watch this File

File Information

matlab2fmex.m is a small translator which aims to convert numerical MATLAB m-files to Fortran90 mex files. matlab2fmex first translates an m-file to a Fortran90 mex source file then compiles that Fortran90 file using MATLAB's mex and the local compiler. Also available at the sourceforge:

MATLAB release MATLAB 6.0 (R12)
Other requirements fortran90 compiler
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
24 Jan 2012 Nedialko

Nedialko (view profile)

Something I learned through this exercise is that Fortran 90 apparently provides
array programming features as in the following line of code:


which computes the $L_{dim}$ norm of the $1 \times n$ array in_1,
without the use of any loop.

24 Jan 2012 Nedialko

Nedialko (view profile)

I find this a very limited tool;
it is by far not robust and the 'documentation'
is not around the right priorities.

Admittedly, it's a tough job to translate between
Matlab = an array programming language with zillions of readily available 'library' functions


Fortran = a strong typed language, whose even later flavours may still be a bit 'deficient' as to handling
and declaring arrays; not to mention that one needs the Diogenes lantern to look around for
zillions of libraries, scattered around the Net (i.e NOT readily available !), that barely implement
a subset of Matlab's 'core' vector-matrix math

As said, I find the approach taken by matlab2fmex as utmostly unappealing in its:

* all-or-nothing approach: you won't get a single .F90 line out unless you:
a) think small, and
b) are ready to go back
to the drawing board of your ORIGINAL Matlab code to make it compatible with the tons of matlab2fmex's
(sometimes very unintuitive) rigid constraints

* that a long list of Matlab-inspired operator-primitives will accompany every teeny bit of user function;
instead of having directed the user to a matlab2fmex 'standard' .F90 module, from which to pick primitives that are ACTUALLY NEEDED.

* that it ambitions to go all the way to actual mex compilation:
a) this is a non-sequitur (see above)
b) it loads the translations with yet another layer (the mex one) of human-unintelligible .F90 code

* All this is made 'turn key' for a beginner in both Matlab and Fortran?!
No kidding guys!


Overall: yet another poor semi-automatic translator

05 Sep 2008 John Brown

The final version I found at is 1.21, which is released in 2005. Is there newer version of this GREAT tool!? I love this tool very much. Please DO NOT stop to update it.

30 Nov 2007 jun ziyang

Great tools!
But I found it can't deal with the following kind of code:

pt(indFPS,1) = signalGenerator(t,...

Anyone knows how to modify matlab2fmex to do the job?


30 May 2006 Michal Kvasnicka

Very useful tool for number crunching apps.

25 Mar 2006 Egemen Kolemen

There is a problem with the "matlab2fmex" function's call to regexp & regexprep. I am using matlab 6.5. You need to use 'tokenize' options in order to specify '$' in these two matlab functions. Below I posted the fixed version. All I did was to add a 'tokenize' option in all the calls to regexp & regexprep then everything works fine.

2 more problems you may face while using these functions:
1. the variables are not case sensitive. if you use both t and T as variables in the m file, you'll get an error.
2. don't do any calculations within the brackest i.e. convert d=[ a; a+b] to c=a+b; d=[a;c];
Additionally, the convertion make a local copy of the data before calling the function to be evaluated which is less than optimal when dealing with big data sets. You can avoid this by using pointers. See
for details.

18 Nov 2005 Christopher Hoen

How do I extract the content of the file that I download?

Have tried Cygwin tar and WinZip, but noen of them works. The name of the file seems strange also:


Comment only
06 Feb 2004 turbulence student

thanks a lot!

Comment only
22 Nov 2005

Service release

Contact us