Hello Kailash Suppose that I have the C routine bellow. This routine
calculate the factorial of n. Suppose that you dont want
translate this routine for Matlab function or script.
So you can use the mex command. In the Matlab prompt you
type (or you can call the command in a Matlab script ou
>>mex -g fact.c (for example there are much more options)
>>mex -g fact.for (if your code is in Fortran)
this creat a file: fact.dll.
Now suppose that you have a Matlab script factorial.m , you
can call the fact C function from factorial.m :
of course the paramater n is necessary.
Can you see this is good if you have several functions
write in C ou Fortran.
Now suppose that you type in the Matlab prompt:
>>mex -setup [enter]
In Matlab 6.0 (12) the following mensage appear:
Please choose your compiler for building external interface (MEX)
Would you like mex to locate installed compilers [y]/n? n
Select a compiler:
 Borland C++Builder version 5.0
 Borland C++Builder version 4.0
 Borland C++Builder version 3.0
 Borland C/C++ version 5.02
 Borland C/C++ version 5.0
 Borland C/C++ (free command line tools) version 5.5
 Compaq Visual Fortran version 6.1
 Digital Visual Fortran version 6.0
 Digital Visual Fortran version 5.0
 Lcc C version 2.4
 Microsoft Visual C/C++ version 6.0
 Microsoft Visual C/C++ version 5.0
 WATCOM C/C++ version 11
 WATCOM C/C++ version 10.6
Theses are the default Fortran and C compilers in Matlab 6.0 (12).
The Lcc C in provide by Matlab, the other is necessary to install.
I would like to use a different Fortran compiler: The Force.
But I dont have sucess at the moment. I think there is necessary
specify the path but don't know to do this.
I would appreciate any help.
* fact.c - returns the factorial of a non-negative integer.
* MATLAB usage: p = fact(n)
void mexFunction( int nlhs, mxArray *plhs,
int nrhs, const mxArray *prhs )
double n, j, *p;
n = mxGetScalar(prhs);
plhs = mxCreateDoubleMatrix(1, 1, mxREAL);
p = mxGetPr(plhs);
j = 1.0;
for (i = n; i > 1; i--)
j = j * i;
*p = j;
--- In , mailing.list@s... wrote:
> How do we run a fortran written subroutine in matlab? Any example.
> Kailash N. Srivastava