File Exchange

matlab2fmex

version 1.0.0.0 (156 KB) by
matlab2fmex.m is a small translator which aims to convert numerical M-files to Fortran90 mex.

Updated 23 Nov 2005

Editor's Note: 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.

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:
https://sourceforge.net/projects/matlab2fmex/

Cite As

Ben Barrowes (2021). matlab2fmex (https://www.mathworks.com/matlabcentral/fileexchange/4443-matlab2fmex), MATLAB Central File Exchange. Retrieved .

Nedialko

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

out=sum(abs(in_1(1,:))**dim)**(1/dble(dim))

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

Nedialko

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

to

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

John Brown

The final version I found at sourceforge.net 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.

jun ziyang

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

pt(indFPS,1) = signalGenerator(t,...
[pump.forwardPower(:);signal.forwardPower(:)]./1000,...
[pump.forwardShape(:);signal.forwardShape(:)],...
[pump.forwardT0(:),signal.forwardT0(:)],...
[pump.forwardRep(:),signal.forwardRep(:)]);

Anyone knows how to modify matlab2fmex to do the job?

thanks.

Michal Kvasnicka

Very useful tool for number crunching apps.

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
http://www.physik3.gwdg.de/~engster/mex_fortran90.html
for details.

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:

matlab2fmex-examples_1.1.tar.tar

turbulence student

good!
thanks a lot!

MATLAB Release Compatibility
Created with R12
Compatible with any release
Platform Compatibility
Windows macOS Linux