Add your own alternative version
Stats
373.9K views 7.5K downloads 39 bookmarked
Posted
20 Sep 2003

Comments and Discussions



hi,
thank you for your sharing.
would you please tell me : is the file "Matlab.h" missing? where to download?







Is that what the MEX file all about?
I am doing a project in fingerprint identification system to be implemented on an FPGA platform.I have made the matlab code but unfortunately the FPGA software requires the functions to be in C or c++.






Hi,
I've used a function from matlab library (normrand) in order to generate random numbers with normal distribution. Now I'm going to use such function in my program which is in Visual C#. How could I do this?
Is it correct to create a .dll file with c++ compiler and then use ".net framework" procedures to use a C code in my C# program?
In fact creating a .dll file from a matlab .m file is not still clear for me?
Is there anybody who could help me?
Thanks for your cooperation





There is a code available on the site "http://www.codeproject.com/KB/cpp/mexFunction.aspx"
Please tell me how to run that code. And where to save those files in detail...
You can contact me at linda_mgnl@hotmail.com
Waiting for your reply..





Dear Rizvi and all Reviewers,
I am Ajay Dashora (email: ajaydashora@gmail.com).
I am using MATLAB (version 2009b) and trying to convert a MATLAB user defined function (first.m) to a C shared library (dll) so as to use it in one of the C code in as a function call. Further, the funtion "first.m" calls two other user defined functions ("second.m" and "third.m") with some user defined library function ("one.m" and "two.m"). I have following quarries regarding the conversion of this MATLAB code to C shared library:
1) I am using following command to createa a dll (libFirst.dll) and afterwards I want to compile this created lib file with c code using mbuild. Following command is appropriate:
mcc t L C W lib:libFirst T link:lib h first.m libmmfile.mlib
2) Should I create the dll through mcc command for only "first.m" or should I generate the dll by mentioning all "user defined structured functions" on command line? Please note that I will not use the created code second.c and third.c in any program. Please advice...
3) Further, how should I treat the "user defined library functions" for creating the dll and later compilation? Please advice...
4) After creating the dll, I want to call this 'function' in C code. The C code address the input argument vector by 'indv' for evaluating the function. How should I define the variable 'x', which is an array, in the main function of C code for evaluating this "Function"? Please advice....
5) One of the "user defined function" which is important for calculating the "Function" read the value of some data from Excel Sheet (using xlsread). How can I use the xlsread command in External Interfaces? Do I need a additional treatment of this, for successfully calling the "MATLAB written Function" in C code? Please advice...
Request your assistance for this issue.
In anticipation of an early reply from you, I remain...
Best Regards,
Ajay





AssalamoAlikum bro, I am working on matlab and want to convert the mfile into a .exe format so that i can write it onto a microcontroller and run it. Please help me............





Asalamulaikum
I need a project that is based on neural networks using any program ( matlab, c++, prolog, n etc).
If you could be of any help i will be very grateful. please.
I'm on a dead line with my projects date. I know I've said on such a short notice but a project on neural networks is hard to find which has not been uploaded on the internet. Kindly help me in this regard please.
Thankyou!
I will be waiting for you response. email : sameenhkhan@hotmail.com
Sameen





Hi I having some problems with the mex stuff. Im working on a c++ project, which uses the boost libraries, so im including files like the following: #include <boost/numeric/ublas/vector.hpp> But when I try to compile it from matlab, it doesnt work I tried: mex mexi.cpp L/boostlib/boost/numeric/ublas lvector.hpp and a dozen other similar stuff. Id really be thankful, if smbody could help me, I gotta find this out for my project work and have no clue. Thanks so much Nisha K





Can U please tell me the link from which
I can download
"MCC  MATLAB to C/C++ compiler" ?
Regards,
Arun Kumar.A





i need help to make a network to predict geomagnetic field using the Gufm1model





Hi.
I want to create mex file (.mexw32) from .m file in Matlab 7.1.
It seems that it is no longer supported. I used to call
mcc x in Matlab 6.5.1 to generate .dll files that i can run
in Matlab. How do I do that in 7.1? Thanks for the help.





hi
I appreciate your effort very much.
when I compile a mex file in matlab, it could not find all the headers files (.h) needes ... I always have a massege of type " Can not includ ....h file) , althought the h file is placed in the include directory in matlab root .. and in the current directory
would you please help me?
best regards
Majd





Hi everybody!
I try to compile the following myfile.c file with the mex functionality of Matlab but it does not work.I get the message:
Mex file entry point is missing. Please check the (casesensitive)
spelling of mexFunction (for C MEXfiles), or the (caseinsensitive)
spelling of MEXFUNCTION (for FORTRAN MEXfiles). ??? Invalid MEXfile 'C:\MATLAB71\extern\myfile.mexw32': The specified module could not be found.
How should I write a mexfunction in the .C code?
The file myfile.c (performs a statistical test) is the following:
 myfile.c 
#include
#include
#include
#define max(a,b) a>b?a:b
double T2,*h;
//returns T2 statistics
void redun(double *x, double *y, int N, int m, int mmax, double
epsilon)
{
int i, j, s;
int IYij, IXYij, IYZij, IXYZij;
double disx, disy, disz, *Cy, *Cxy, *Cyz, *Cxyz, mu;
mu=pow(2.0*epsilon,m+2*mmax+1);
Cy = (double *) malloc(N*sizeof(double));
Cxy = (double *) malloc(N*sizeof(double));
Cyz = (double *) malloc(N*sizeof(double));
Cxyz = (double *) malloc(N*sizeof(double));
for (i=0;i!=N;i++)
h[i] = Cy[i] = Cxy[i] = Cyz[i] = Cxyz[i] = 0.0;
T2=0.0;
for (i=mmax;i!=N;i++)
{
Cy[i]=Cxy[i]=Cyz[i]=Cxyz[i]=0.0;
for (j=mmax;j!=N;j++)
if (j!=i)
{
disx = disy = 0.0;
for (s=1;s!=m+1;s++)
disx = max(fabs(x[is]x[js]),disx);
for (s=1;s!=mmax+1;s++)
disy = max(fabs(y[is]y[js]),disy);
if (disy <= epsilon)
{
Cy[i]++;
if (disx <= epsilon)
{
Cxy[i]++;
}
disz = max(fabs(y[i]y[j]),disy);
if (disz <= epsilon)
{
Cyz[i]++;
if (disx <= epsilon)
{
Cxyz[i]++;
}
}
} // end condition Yi  Yj < epsilon
} // end loop over j
Cy[i] /= (double)(Nmmax);
Cxy[i] /= (double)(Nmmax);
Cyz[i] /= (double)(Nmmax);
Cxyz[i] /= (double)(Nmmax);
h[i] += 2.0/(double) mu*(Cxyz[i]*Cy[i]  Cxy[i]*Cyz[i])/6.0;
}
for (i=mmax;i!=N;i++)
{
for (j=mmax;j!=N;j++)
if (j!=i)
{
IYij = IXYij = IYZij = IXYZij = 0;
disx = disy = 0.0;
for (s=1;s!=m+1;s++)
disx = max(fabs(x[is]x[js]),disx);
for (s=1;s!=mmax+1;s++)
disy = max(fabs(y[is]y[js]),disy);
if (disy <= epsilon)
{
IYij=1;
if (disx <= epsilon)
IXYij = 1;
disz = max(fabs(y[i]y[j]),disy);
if (disz <= epsilon)
{
IYZij = 1;
if (disx <= epsilon)
IXYZij = 1;
}
} // end condition Yi  Yj < epsilon
h[i] += 2.0/(double) mu*(Cxyz[j]*IYij + IXYZij*Cy[j] 
Cxy[j]*IYZij  IXYij*Cyz[j])/(double)(6*(Nmmax));
} // end second loop over j
} // end loop over i
for (i=mmax;i!=N;i++)
T2 += h[i];
T2 /= (double)(Nmmax);
for (i=mmax;i!=N;i++)
h[i] = T2;
free (Cy);
free (Cxy);
free (Cxyz);
free (Cyz);
}
void InsertionSort(double *X, int *S, int M)
{
int i, *I;
int j;
int r;
double R;
I= (int*) malloc (M*sizeof(int));
for (i=0;i I[i]=i;
for (i=1; i {
R = X[i];
r = i;
for (j=i1; (j>=0) && (X[j]>R); j)
{
X[j+1] = X[j];
I[j+1] = I[j];
}
X[j+1] = R;
I[j+1] = r;
}
for (i=0; i S[I[i]]=i;
}
void uniform (double *X, int M)
{
int *I, i;
I = (int*) malloc (M*sizeof(int));
InsertionSort(X, I, M);
for (i=0;i X[i] = (double) I[i]/M*3.464101615; // to make unit
variance
}
/* normalize the time series to unit std. dev. */
void normalise(double *x, int N)
{
int i;
double mean=0.0, var=0.0;
for (i=0;i!=N;i++)
{
mean += x[i];
var += x[i]*x[i];
}
mean /= (double)(N);
var /= (double)(N);
var = mean*mean;
for (i=0;i!=N;i++)
x[i] = (x[i]mean)/sqrt(var);
return;
}
int main(int num_par, char *par[])
{
char infil1name[128]="test1.txt",infil2name[128]="test2.txt",
outfilname[128];
double *x, *y, tmp, epsilon=.50, VT2, p_T2, p_T21, *ohm, *cov,
T2_TVAL, T2_TVAL1, sigma[4][4];
int i, j, l, k, m=1, K, N;
long seed;
FILE *infil1, *infil2, *outfil;
// enter parameters from outside
if (num_par==1)
{
printf("Input file containing series 1: ");
scanf("%s", infil1name);
}
else
{
i=0;
do
{
infil1name[i]=par[1][i];
i++;
}
while (par[1][i1]!='\0');
}
if ( (infil1=fopen(infil1name,"r")) == NULL)
{
fprintf(stderr,"\nError: unable to open file containing series
1...%s\n",infil1name);
exit(1);
}
i = 0;
while (fscanf(infil1,"%lf", &tmp) != EOF)
{
i++;
}
fclose(infil1);
N=i;
if (num_par<3){
printf("Input file containing series 2: ");
scanf("%s", infil2name);
}
else
{
i=0;
do
{
infil2name[i]=par[2][i];
i++;
}
while (par[2][i1]!='\0');
}
if ( (infil2=fopen(infil2name,"r")) == NULL)
{
fprintf(stderr,"\nError: unable to open file containing series
2.\n");
exit(1);
}
i=0;
while (fscanf(infil2,"%lf", &tmp) != EOF)
{
i++;
}
fclose(infil2);
if ( i!=N)
{
fprintf(stderr,"\nError: files contain series of different
length.\n");
}
if (num_par<4)
{
printf("Input embedding dimension: ");
scanf("%d", &m);
}
else
m=atoi(par[3]);
if (num_par<5)
{
printf("Input bandwidth: ");
scanf("%lf", &epsilon);
printf("\n");
}
else
epsilon=atof(par[4]);
x = (double *) malloc(N*sizeof(double));
y = (double *) malloc(N*sizeof(double));
h = (double *) malloc(N*sizeof(double));
K = (int)(sqrt(sqrt(N)));
ohm = (double *) malloc(K*sizeof(double));
cov = (double *) malloc(K*sizeof(double));
// read the series
infil1=fopen(infil1name,"r");
infil2=fopen(infil2name,"r");
for (i=0;i {
fscanf(infil1,"%lf",&(x[i]));
fscanf(infil2,"%lf",&(y[i]));
}
normalise(x,N);
normalise(y,N);
// redun(x,y, ..) test statistic for X > Y
redun(x,y,N,m,m,epsilon);
ohm[0] = 1.0;
for (k=1;k ohm[k] = 2.0*(1.0k/(double)(K));
/* determine autocovariance of h[i] */
for (k=0;k!=K;k++)
{
cov[k] = 0.0;
for (i=m+k;i!=N;i++)
cov[k] += h[i]*h[ik];
cov[k] /= (double)(Nmk);
}
T2_TVAL=VT2=0.0;
/* variance of T2 */
for (k=0;k!=K;k++)
VT2 += 9.0*ohm[k]*cov[k];
T2_TVAL = T2*sqrt(Nm)/sqrt(VT2);
if (T2_TVAL>0)
p_T2 = 0.5  .5*erf(T2_TVAL/sqrt(2.0));
else
p_T2 = 0.5 + .5*erf(T2_TVAL/sqrt(2.0));
if ((num_par<6)  ((outfil=fopen(par[5],"w")) == NULL))
outfil=stdout;
else printf("The results are saved to the file: %s\n",par[5]);
fprintf(outfil,"Series length=%d, embedding dimension=%d,
bandwidth=%f\n",N,m,epsilon);
fprintf(outfil,"\nNull hypothesis: %s does not cause
%s\n",infil1name,infil2name);
fprintf(outfil,"T statistics=%.3f, pvalue=%1.5f\n",T2_TVAL,p_T2);
redun(y,x,N,m,m,epsilon);
ohm[0] = 1.0;
for (k=1;k ohm[k] = 2.0*(1.0k/(double)(K));
/* determine autocovariance of h[i] */
for (k=0;k!=K;k++)
{
cov[k] = 0.0;
for (i=m+k;i!=N;i++)
cov[k] += h[i]*h[ik];
cov[k] /= (double)(Nmk);
}
T2_TVAL=VT2=0.0;
/* variance of T2 */
for (k=0;k!=K;k++)
VT2 += 9.0*ohm[k]*cov[k];
T2_TVAL = T2*sqrt(Nm)/sqrt(VT2);
if (T2_TVAL>0)
p_T2 = 0.5  .5*erf(T2_TVAL/sqrt(2.0));
else
p_T2 = 0.5 + .5*erf(T2_TVAL/sqrt(2.0));
fprintf(outfil,"\nNull hypothesis: %s does not cause
%s\n",infil2name,infil1name);
fprintf(outfil,"T statistics=%.3f, pvalue=%1.5f\n",T2_TVAL,p_T2);
fcloseall();
return(0);
}
sotiria





Hi everybody!
I try to compile the following myfile.c file with the mex functionality of Matlab but it does not work.I get the message:
Mex file entry point is missing. Please check the (casesensitive)
spelling of mexFunction (for C MEXfiles), or the (caseinsensitive)
spelling of MEXFUNCTION (for FORTRAN MEXfiles). ??? Invalid MEXfile 'C:\MATLAB71\extern\myfile.mexw32': The specified module could not be found.
How should I write a mexfunction in the .C code?
The file myfile.c (performs a statistical test) is the following:
 myfile.c 
#include
#include
#include
#define max(a,b) a>b?a:b
double T2,*h;
//returns T2 statistics
void redun(double *x, double *y, int N, int m, int mmax, double
epsilon)
{
int i, j, s;
int IYij, IXYij, IYZij, IXYZij;
double disx, disy, disz, *Cy, *Cxy, *Cyz, *Cxyz, mu;
mu=pow(2.0*epsilon,m+2*mmax+1);
Cy = (double *) malloc(N*sizeof(double));
Cxy = (double *) malloc(N*sizeof(double));
Cyz = (double *) malloc(N*sizeof(double));
Cxyz = (double *) malloc(N*sizeof(double));
for (i=0;i!=N;i++)
h[i] = Cy[i] = Cxy[i] = Cyz[i] = Cxyz[i] = 0.0;
T2=0.0;
for (i=mmax;i!=N;i++)
{
Cy[i]=Cxy[i]=Cyz[i]=Cxyz[i]=0.0;
for (j=mmax;j!=N;j++)
if (j!=i)
{
disx = disy = 0.0;
for (s=1;s!=m+1;s++)
disx = max(fabs(x[is]x[js]),disx);
for (s=1;s!=mmax+1;s++)
disy = max(fabs(y[is]y[js]),disy);
if (disy <= epsilon)
{
Cy[i]++;
if (disx <= epsilon)
{
Cxy[i]++;
}
disz = max(fabs(y[i]y[j]),disy);
if (disz <= epsilon)
{
Cyz[i]++;
if (disx <= epsilon)
{
Cxyz[i]++;
}
}
} // end condition Yi  Yj < epsilon
} // end loop over j
Cy[i] /= (double)(Nmmax);
Cxy[i] /= (double)(Nmmax);
Cyz[i] /= (double)(Nmmax);
Cxyz[i] /= (double)(Nmmax);
h[i] += 2.0/(double) mu*(Cxyz[i]*Cy[i]  Cxy[i]*Cyz[i])/6.0;
}
for (i=mmax;i!=N;i++)
{
for (j=mmax;j!=N;j++)
if (j!=i)
{
IYij = IXYij = IYZij = IXYZij = 0;
disx = disy = 0.0;
for (s=1;s!=m+1;s++)
disx = max(fabs(x[is]x[js]),disx);
for (s=1;s!=mmax+1;s++)
disy = max(fabs(y[is]y[js]),disy);
if (disy <= epsilon)
{
IYij=1;
if (disx <= epsilon)
IXYij = 1;
disz = max(fabs(y[i]y[j]),disy);
if (disz <= epsilon)
{
IYZij = 1;
if (disx <= epsilon)
IXYZij = 1;
}
} // end condition Yi  Yj < epsilon
h[i] += 2.0/(double) mu*(Cxyz[j]*IYij + IXYZij*Cy[j] 
Cxy[j]*IYZij  IXYij*Cyz[j])/(double)(6*(Nmmax));
} // end second loop over j
} // end loop over i
for (i=mmax;i!=N;i++)
T2 += h[i];
T2 /= (double)(Nmmax);
for (i=mmax;i!=N;i++)
h[i] = T2;
free (Cy);
free (Cxy);
free (Cxyz);
free (Cyz);
}
void InsertionSort(double *X, int *S, int M)
{
int i, *I;
int j;
int r;
double R;
I= (int*) malloc (M*sizeof(int));
for (i=0;i=0) && (X[j]>R); j)
{
X[j+1] = X[j];
I[j+1] = I[j];
}
X[j+1] = R;
I[j+1] = r;
}
for (i=0; i Y
redun(x,y,N,m,m,epsilon);
ohm[0] = 1.0;
for (k=1;k0)
p_T2 = 0.5  .5*erf(T2_TVAL/sqrt(2.0));
else
p_T2 = 0.5 + .5*erf(T2_TVAL/sqrt(2.0));
if ((num_par<6)  ((outfil=fopen(par[5],"w")) == NULL))
outfil=stdout;
else printf("The results are saved to the file: %s\n",par[5]);
fprintf(outfil,"Series length=%d, embedding dimension=%d,
bandwidth=%f\n",N,m,epsilon);
fprintf(outfil,"\nNull hypothesis: %s does not cause
%s\n",infil1name,infil2name);
fprintf(outfil,"T statistics=%.3f, pvalue=%1.5f\n",T2_TVAL,p_T2);
redun(y,x,N,m,m,epsilon);
ohm[0] = 1.0;
for (k=1;k0)
p_T2 = 0.5  .5*erf(T2_TVAL/sqrt(2.0));
else
p_T2 = 0.5 + .5*erf(T2_TVAL/sqrt(2.0));
fprintf(outfil,"\nNull hypothesis: %s does not cause
%s\n",infil2name,infil1name);
fprintf(outfil,"T statistics=%.3f, pvalue=%1.5f\n",T2_TVAL,p_T2);
fcloseall();
return(0);
}
sotiria





Hi,
i'v a question ...
i'm trying to setup c++ compiler(not located)
(mex setup)...
after running a make file that uses mex, compiler couldn't be found ?!?...
message:
C:\PROGRAMME\MATLAB71\BIN\MEX.PL: Error: Unable to locate compiler.
Use mex setup to configure your environment properly.
Is there any special option to setup mex correctly in this case?
i'll be very glad to have your answer!
nina
 modified at 4:38 Tuesday 25th July, 2006





Salam
Did you use mex Setup? Did you follow the instructions?
Best regards,
A. Riazi





Hi again,
Ye!
is exactly what i did!
just like mex description!
It gives me:
Try to update options file: C:\Dokumente und Einstellungen\nina.MATRIXWARE\Application Data\MathWorks\MATLAB\R14SP3\mexopts.bat
From template: C:\PROGRAMME\MATLAB71\BIN\win32\mexopts\msvc50opts.bat
Done . . .
***************************************************************************
Warning: The file extension of 32bit Windows MEXfiles was changed
from ".dll" to ".mexw32" in MATLAB 7.1 (R14SP3). The generated
MEXfile will not be found by MATLAB versions prior to 7.1.
Use the output option with the ".dll" file extension to
generate a MEXfile that can be called in previous versions.
For more information see:
MATLAB 7.1 Release Notes, New File Extension for MEXFiles on Windows
***************************************************************************
i guess it's something with mex.pl (so that i'd said last time!)i've no idea how i could find the problem of this mex.pl!!!
best regards
nina





Hi again,
it's my problem:
it could not find cl.exe file, how should I configure mex setup ??
make
Could not find the compiler "cl" on the DOS path.
Use mex setup to configure your environment properly.
the makefile is:
% This make.m is used under Windows
mex O c svm.cpp
mex O c svm_model_matlab.c
mex O svmtrain.c svm.obj svm_model_matlab.obj
mex O svmpredict.c svm.obj svm_model_matlab.obj
could you tell me what is wrong?
thanx,
nina





Hi Mr. Riazi
I'v downloaded "mpgread" & "mpgwrite" packages(which are used to convert MPEG video files to matlab standard movie files & vice versa. But when I debug & run makedll.m file & then call mpgread, for example, in matlab command window ([R, G, B] = mpgread('f:\foreman.mpg', [1:20]);) this error message is shown:

Segmentation violation detected at Mon Jul 05 02:52:27 2004

Configuration:
MATLAB Version: 7.0.1.24704 (R14) Service Pack 1
MATLAB License: 238685
Operating System: Microsoft Windows XP
Window System: Version 5.1 (Build 2600: Service Pack 2)
Processor ID: x86 Family 15 Model 2 Stepping 9, GenuineIntel
Virtual Machine: Java 1.4.2_04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM
(mixed mode)
Default Charset: ibm5348_P1001997
Register State:
EAX = 00000000 EBX = 00000001
ECX = 16131008 EDX = 11081da0
ESI = 0e0fafa4 EDI = 00000006
EBP = 00cddc74 ESP = 00cddc18
EIP = 0e0e774c FLG = 00210246
Stack Trace:
[0] mpgread.dll:0x0e0e774c(1, 0x0e0fafa4, 47, 0x11081d80)
[1] mpgread.dll:0x0e0e4b32(0x11081d80, 0x00cde6ac, 0x0e0faf90, 0)
[2] mpgread.dll:0x0e0e2c6a(0, 0x11081d80, 0x00cde6ac, 0)
[3] mpgread.dll:0x0e0e1cce(3, 0x00cde6ac, 2, 0x00cde70c)
[4] libmex.dll:_mexRunMexFile(3, 0x00cde6ac, 2, 0x00cde70c) + 103 bytes
[5] libmex.dll:public: virtual void __thiscall Mfh_mex::dispatch_file(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(3, 0x00cde6ac, 2, 0x00cde70c) + 157 bytes
[6] m_dispatcher.dll:public: virtual void __thiscall Mfh_file::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(3, 0x00cde6ac, 2, 0x00cde70c) + 273 bytes
[7] m_interpreter.dll:int __cdecl mdDispatch(int,char const *,int,struct mxArray_tag * *,int,struct mxArray_tag * *,class Mfh_MATLAB_fn * *)(487, 0x110ff40c "mpgread", 3, 0x00cde6ac) + 88 bytes
[8] m_interpreter.dll:_inDispatchFromStack(487, 0x110ff40c "mpgread", 3, 2) + 801 bytes
[9] m_interpreter.dll:enum opcodes __cdecl inDispatchCall(char const *,int,int,int,int *,int *)(0x110ff40c "mpgread", 487, 3, 2) + 138 bytes
[10] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *)(2, 0, 0, 0) + 2359 bytes
[11] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *)(2, 0, 0, 0) + 272 bytes
[12] m_interpreter.dll:_inInterPcode(2, 0x78773d54, 0, 0) + 69 bytes
[13] m_interpreter.dll:enum inExecutionStatus __cdecl in_local_call_eval_function(int *,struct _pcodeheader *,int *,struct mxArray_tag * * const,enum inDebugCheck)(0x00cdf2c8, 0x00cdf3b4, 2, 1) + 162 bytes
[14] m_interpreter.dll:$L73181(0x78773d54, 0x0f954cd0 "[R, G, B] = mpgread('f:\foreman...", 0, 0) + 196 bytes
[15] m_interpreter.dll:enum inExecutionStatus __cdecl inEvalCmdWithLocalReturnandtype(char const *,int *,enum inDebugCheck)(0x0f954cd0 "[R, G, B] = mpgread('f:\foreman...", 0, 2, 0x00cdf444 "ôôÍ") + 69 bytes
[16] m_interpreter.dll:_inEvalCmdNoEnd(0x0f954cd0 "[R, G, B] = mpgread('f:\foreman...", 0x00cdf4e4, 0x00cdf49c, 0x01493f28) + 16 bytes
[17] bridge.dll:_mnParser(0x7c80b529, 0x01493f28, 0, 0) + 431 bytes
[18] mcr.dll:public: void __thiscall mcrInstance::mnParser(void)(271268, 0x4d5c3a45, 0x6f6a6861, 0x4d5c6275) + 87 bytes
[19] MATLAB.exe:0x00401d2f(4194304, 0, 271268, 0x01493f28)
[20] MATLAB.exe:0x00403e45(0x00c5dd60, 0x7c90e1fe "¸±", 0x7ffda000, 0x8054a938)
[21] kernel32.dll:0x7c816d4f(0x00403cc0 "jth8U@", 0, 0, 0)
This error was detected while a MEXfile was running. If the MEXfile
is not an official MathWorks function, please examine its source code
for errors. Please consult the External Interfaces Guide for information
on debugging MEXfiles.
If it is an official MathWorks function, please
follow these steps in reporting this problem to The MathWorks so
that we have the best chance of correcting it:
1. Send this crash report to segv@mathworks.com for automated analysis.
For your convenience, this information has been recorded in:
C:\DOCUME~1\TCTTOH~1\LOCALS~1\Temp\matlab_crash_dump.3800
2. Also, if the problem is reproducible, send the crash report to
support@mathworks.com along with:
 A specific list of steps that will reproduce the problem
 Any M, MEX, MDL or other files required to reproduce the problem
 Any error messages displayed to the command window
A technical support engineer will contact you with further information.
Thank you for your assistance. Please save your workspace and restart
MATLAB before continuing your work.
//////////////////////////////////////////////////////////
Please help me to solve the problem.
Thanks in advance & best regards
H Mahjoub
 modified at 20:01 Wednesday 5th July, 2006





Hi,
First of all I would like to congratulate you for your articles, that I found to be very good and very informative.
The question I have to you is if it is possible to do this exact task using Lcc, instead of Microsoft visual Basic C++ ? The problem is that my company doesn't have VC++, so as we need to call C functions from matlab, I was thinking if it is possible to do this task using other compiler.
My MatLab version is R2006a.
Best regards,
Pedro Cardoso





In theory you can use LCC, Watcom, Borland and Microsoft compilers. For other compilers than VC++, you must use proper libraries and preprocessors. Just read MATLAB Compiler documents and also refer to its site.
Best regards,
A. Riazi





Hi,
Thank you for your answer. But what's the easier way to call C functions from MatLab ? I tried a simple example that adds two numbers, and it worked correctly, but now I want to make a MEX file that has several functions and call each one of them. The goal is to use a C software from ITU (ITUR P.452). This software has lots of functions, to read/write from/to a file and do propagation calculations. What can I do to overcome this obstacle ? I searched all over the internet and I can't create a MEX that works with the software.
Best regards,
Pedro Cardoso





Dear Sir,
I am very much new to matlab...please tell me the following things... do i need matlab installed on the computer where i want to ship my application developed in vc++ using matlab max file and compiled though mcc and created a lib file....
thanks





Hi
There is no need to install MATLAB to target machine but you have to install MATLAB redistributable files. Please check Mathworks.com for more info.
Best regards,
A. Riazi





Hi,
I created a new Sfunction from scratch copy of sfun_basic.c file & included my code in. I need to call some functions that are defined in a DLL file. How to include the dll in my code?
Thanks





Hi,
Basically you must include the DLL header file to your code and also import its library (*.lib).
Best regards,
A. Riazi





Thanks for your reply, but how this can be reached? to import the dll files with the c file created?
Thanks again





Hi,
I create a mex project a dll C++ project.
My project contains many files, but it's under one dll.
I will give you an example how I am using my dll.
(Suppose I want to call FFT,
mexProject('FFT') ; mexProject is name of the dll,FFT is the routine)
I am using a database that a created from a MAT file.
I created my database on matlab and with a program I managed to pass it to c++, as a result I have an header and cpp file.
Exapmle:
The cpp contains
############################################################
#include "type_def.h"
#include "phydb_m2h_rf_front_tx.h"
namespace M2HPhyRfFrontTx
{
char __MAT2H_RF_FRONT_TX_bw[3]={50, 53, 0};
SPYWORD __MAT2H_RF_FRONT_TX_Coeff[129]={0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F
, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000001F, 0.000000F, 0.000002F, 0.000003F, 0.000001F, 0.000008F
, 0.000007F, 0.000009F, 0.000022F, 0.000004F, 0.000037F, 0.000043F, 0.000025F, 0.000100F, 0.000048F, 0.000125F
, 0.000193F, 0.000031F, 0.000339F, 0.000249F, 0.000315F, 0.000657F, 0.000082F, 0.000919F, 0.000900F, 0.000597F
, 0.001808F, 0.000639F, 0.002052F, 0.002586F, 0.000764F, 0.004211F, 0.002352F, 0.003866F, 0.006296F, 0.000189F
, 0.008609F, 0.006592F, 0.006244F, 0.013714F, 0.002569F, 0.016193F, 0.016273F, 0.008734F, 0.028955F, 0.011380F
, 0.031037F, 0.041914F, 0.010655F, 0.075389F, 0.051658F, 0.101508F, 0.298287F, 0.388619F, 0.298287F, 0.101508F
, 0.051658F, 0.075389F, 0.010655F, 0.041914F, 0.031037F, 0.011380F, 0.028955F, 0.008734F, 0.016273F, 0.016193F
, 0.002569F, 0.013714F, 0.006244F, 0.006592F, 0.008609F, 0.000189F, 0.006296F, 0.003866F, 0.002352F, 0.004211F
, 0.000764F, 0.002586F, 0.002052F, 0.000639F, 0.001808F, 0.000597F, 0.000900F, 0.000919F, 0.000082F, 0.000657F
, 0.000315F, 0.000249F, 0.000339F, 0.000031F, 0.000193F, 0.000125F, 0.000048F, 0.000100F, 0.000025F, 0.000043F
, 0.000037F, 0.000004F, 0.000022F, 0.000009F, 0.000007F, 0.000008F, 0.000001F, 0.000003F, 0.000002F, 0.000000F
, 0.000001F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F
, 0.000000F, 0.000000F};
char __MAT2H_RF_FRONT_TX_1_bw[3]={53, 48, 0};
SPYWORD __MAT2H_RF_FRONT_TX_1_Coeff[2]={1.000000F, 0.000000F};
char __MAT2H_RF_FRONT_TX_2_bw[4]={49, 48, 48,
0};
##########################################################
and the header files contains
#ifndef M2HPHYRFFRONTTX_H
#define M2HPHYRFFRONTTX_H
namespace M2HPhyRfFrontTx
{
typedef struct
{
char *bw;
UINT16 I;
UINT16 MemSpS;
UINT16 Len;
SPYWORD Delay;
SPYWORD *Coeff;
UINT16 MemLen;
} RF_Front_Tx_DB;
const int RF_FRONT_TXS_LEN=4;
extern RF_Front_Tx_DB RF_FRONT_TXS[4];
} // End Of Namespace M2HPhyRfFrontTx
#endif
#########################################################
I have several files like that, I pass several MAT files
to a C++ files.
I have recognized when I add a few files of database on C++
I am getting the following message :
Invalid MEXfile 'M:\...\mxProject.dll': 'M:\...\mxProject.dll' is not a valid Win32 application.
Please help me.
All the memory allocation are static in my database files.
Thanks,
Shai
All





a friend of mine has written this code where he generates a dll in vc++ complier 6.0 .he links successfully with all libs he needs to generate the dll.this dll had a mexFunction entry point, which somehow gives him an error when he tries to use this dll in matlab command prompt.the error message he gets is
Mex file entry point is missing. Please check the (casesensitive)
spelling of mexFunction (for C MEXfiles), or the (caseinsensitive)
spelling of MEXFUNCTION (for FORTRAN MEXfiles).
??? Invalid MEXfile 'C:\Program Files\OpenCV\samples\c\krishna\LK\Debug\LK.dll': The specified module could not be found.
.
his code where he generates the dll looks like this.he is successfully able to link and generate the dll using VC++ 6.0. he uses matlab R14.
could anyone help ir comment on this problem.
#include "mex.h"
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
#include "stdio.h"
void mexFunction(
int nlhs, // Number of left hand side (output) arguments
mxArray *plhs[], // Array of left hand side arguments
int nrhs, // Number of right hand side (input) arguments
const mxArray *prhs[] // Array of right hand side arguments
)
{
/* Check for proper number of arguments. */
if (nrhs != 1 && nrhs != 2 && nrhs != 3) {
mexErrMsgTxt("One, two, or three inputs required.");
} else if (nlhs > 2) {
mexErrMsgTxt("Too many output arguments");
}
double *image1,*image2,*velocity_x,*velocity_y,*velox, *veloy;
int imysize1,imxsize1,imysize2,imxsize2 ;
int dim[2],i,j,size[2];
int x,y;
unsigned char *im_1,*im_2;
im_1 = (unsigned char *)mxGetData(prhs[0]);
im_2 = (unsigned char *)mxGetData(prhs[1]);
// printf("the value is %c",im_1[2]);
/* Assign pointers to first input image*/
//image1 = mxGetPr(prhs[0]);
imysize1 = mxGetM(prhs[0]);
imxsize1 = mxGetN(prhs[0]);
printf("Input image 1: number of columns: %d, number of rows:%d \n",imxsize1,imysize1);
int no_rows1 = imysize1;
int no_col1 = imxsize1;
int width = no_col1;
int height = no_rows1;
/* Assign pointers to second input image*/
//image2 = mxGetPr(prhs[1]);
imysize2 = mxGetM(prhs[1]);
imxsize2 = mxGetN(prhs[1]);
printf("Input image 2: number of columns: %d, number of rows:%d \n",imxsize2,imysize2);
int no_rows2 = imysize2;
int no_col2 = imxsize2;
/* for(y=0;ydata.ptr[x+y*width] = c;
image_2>data.ptr[x+y*width] = c1;
}
}*/
// printf("\n assignment done\n");
//printf("value at 0 and 0 is %f\n",CV_MAT_ELEM(*image_2,double,0,0));
/* works fine*/
//printf("the unchar pointer value at 0 and 0 is %d\n",(image_2>data.ptr[241]));
//printf("step is %d \n",image_2>step);
/*creation of velocity headers*/
CvMat* velx= cvCreateMatHeader(no_rows1,no_col1,CV_32FC1);
cvCreateData(velx);
CvMat* vely= cvCreateMatHeader(no_rows1,no_col1,CV_32FC1);
cvCreateData(vely);
/*creation of other required parameters*/
const bool use_previous = false;
const double LAMBDA = 100.0f;
CvTermCriteria criteria;
criteria.type = CV_TERMCRIT_ITER;
criteria.max_iter = 64;
criteria.epsilon = 0.01f;
// printf("\n All assignment done\n");
cvCalcOpticalFlowLK(image_1,image_2,cvSize(7,7),velx,vely);
//cvCalcOpticalFlowHS(image_1,image_2,use_previous,velx,vely,LAMBDA,criteria);
// printf("\n lucas kanade done");
dim[0] = imysize1;
dim[1] = imxsize1;
plhs[0] = mxCreateNumericArray(2,dim,mxDOUBLE_CLASS, mxREAL);
velocity_x = mxGetPr(plhs[0]);
plhs[1] = mxCreateNumericArray(2,dim,mxDOUBLE_CLASS, mxREAL);
velocity_y = mxGetPr(plhs[1]);
//printf("Velocity %f \n",CV_MAT_ELEM(*velx,float,5,5));
CvSize size_vel = cvGetSize(velx);
// printf("velocity size width %d height %d \n",size_vel.width,size_vel.height);
for(x=0;xdata.fl[x+y*width];
velocity_y[x+y*width] = vely>data.fl[x+y*width];
//velocity_x[y+x*columns1] = CV_MAT_ELEM(*velx,float,x,y);
//velocity_y[y+x*columns1] = CV_MAT_ELEM(*vely,float,x,y);
//printf("%f\n",velocity_x[y+x*columns1]);
}
}
}





Hi, I'm doing research in TDD(Test Driven Development) in embedded systems. That means writing tests first, and then coding. Right now I am writing some tests for algorithms in MATLAB, and if I want to use the same tests in embedded environment, exp: in C++, the only way is to use MEX file? And I think the translation can only be done manually, not automaticly. I don't know whether my understanding is correct. Thanks a lot.





For Mr.Riazi
I have tried to do the compute prime example. but i could not create the dll successfully. The following are the error messages i recd.
D:\myprojects\mexfunction\mexfunction.cpp(4) : fatal error C1083: Cannot open precompiled header file: 'Debug/mexFunction.pch': No such file or directory
Error executing cl.exe.
Please let me know where i could be wrong. Actually i have used the source code given by you without any change and followed the steps as per your webpage information.
With regards
Sekar





i tried to build this prog which creates a structure and sends it over the comm port it gave me this error
pls tell me what could be wrong?
thank you
Ajo T.

Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 19921998. All rights reserved.
comp3.obj
Creating library _lib8741.x and object _lib8741.exp
comp3.obj : error LNK2001: unresolved external symbol "void __cdecl writecom(struct mxArray_tag *)" (?writecom@@YAXPAUmxArray_tag@@@Z)
comp3.dll : fatal error LNK1120: 1 unresolved externals
D:\MATLAB7\BIN\WIN32\MEX.PL: Error: Link of 'comp3.dll' failed.
??? Error using ==> mex
Unable to complete successfully






sir,
please help me with mex files structure application.
how can we send structures with no field values to mex files and then enter the values in c/c++ program and send it back into matlab?.are the way in which data stored in matlab and c/c++ different ?
thank you for your help
Ajo ,





There is no way to pass a structure to a mex function directly, but you can pass every elements as a seperate matrix to mex function. Here is an example:
[x,y]=myMexFunction(structure.element1, structure.element2, ...);
Best regards,
A. Riazi





Hi,
I would like to implement this routine written in C and to put it in a mexfile... Unfortunally, these matrices of 4 dimensions don't have the same increment... I have thought of that for several days and still have no idea...
void advection( double ****eam_elm,double *cl,int ng,double ****gam)
{
int i,j,k, i1, j1, k1;
for (i=0; i<6; i++)
{
i1 = cl[i];
for (j=0; j<6; j++)
{
j1 = cl[j];
for (k=0; k<6; k++)
{
k1 = cl[k];
gam[j1][i1][k1][1] = gam[j1][i1][k1][1] + eam_elm[j][i][k][1];
gam[j1][i1][k1][2] = gam[j1][i1][k1][2] + eam_elm[j][i][k][2];
}
}
}
}
Thanks in advance for your help,
Rosette.





I need help in writing a code for program using mex files.
program involves one input array of size say 6(boolean array),and some operation on this array, and returns this modified array.
prabhu





Hi Mr. A. Riazi
I have try your example, and it work very well, but when I try to export Intel lib, doesn’t work I followed all the steps that you explain in your example.
Have look for my simple example :
#include "StdAfx.h"
#include "dll_conv.h"
#include "mex.h"
#pragma comment(lib, "libmx.lib")
#pragma comment(lib, "libmat.lib")
#pragma comment(lib, "libmex.lib")
#pragma comment(lib, "libmatlb.lib")
// Add for Intel lib
#include "nspconv.h"
#pragma comment(lib, "nsp.lib")
/* The gateway routine. */
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
double *x, *h, *y;
int nx, nh,cols;
/* get the length of each input vector */
nx = mxGetN(prhs[0]);
nh = mxGetN(prhs[1]);
/* get pointers to the real and imaginary parts of the inputs */
x = mxGetPr(prhs[0]);
h = mxGetPr(prhs[1]);
/* create a new array and set the output pointer to it */
cols = nx + nh  1;
plhs[0] = mxCreateDoubleMatrix(1, cols, mxREAL);
y = mxGetPr(plhs[0]);
nspdConv(x, nx, h, nh, y);
return;
}
This is the errors I have, very strange , I have include nspconv.h (it’s a Intel headers) and the compiler said that we have errors in nspconv.h:
d:\projet\project_exemple_matlab\imprt_lib\signal\headers\nspconv.h(31) : error C2061: syntax error : identifier 'nspdConv'
d:\projet\project_exemple_matlab\imprt_lib\signal\headers\nspconv.h(34) : error C2146: syntax error : missing ';' before identifier 'NSPAPI'
d:\projet\project_exemple_matlab\imprt_lib\signal\headers\nspconv.h(34) : fatal error C1004: unexpected end of file found
thanks





Hi,
I don't understand what you mean for export Intel lib. May be you mean importing Intel library.
Also please check the Intel Library manual for any preprocessor definition that is required for your project.
Best regards,
A. Riazi





yes sorry I mean importing Intel library.
ok I m going to check the Intel Library manual,and I well tel you what new
thanks





Hello
I work in Matlab environment and I want to use some Intel library,(because the Intel lib is already compile and optimize for Intel processor :> ) can you explain my how to call function in Intel library from my mexfunction
Thanks





Hi,
It is very simple to do. Just include the header files of Intel library where you want to use its functions. Then add Intel library files (*.lib) to your project. You can use desired functions in your mex. Here is an example:
#include "some Intel header file.h"
#pragma comment(lib, "the Intel lib file.lib")
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
{
if (nrhs != 1)
{
mexErrMsgTxt("One input required.");
}
else if (nlhs > 1)
{
mexErrMsgTxt("Too many output arguments");
}
YourIntelFunction(some input);
}
Best regards,
A. Riazi





Ok thanks
I’ll do it, and for the path of intel lib, I am obliged to put them in C:\MATLAB6p5\extern\include ?
denham





You have two option,
1 Copy the lib files in folder of your project.
2 Add the path of Intel library headers and lib files to list of Visual Studio: Tools > Options > Directories > Include & Library combo box
Best regards,
A. Riazi





When I add #include "nspconv.h" in my mexfunction( like you show me), I have a lot of errors in a nspconv.h, knowing that this header file its programming by intel
I don’t know what I can do !!
Thanks





Hello!
I'm having a problem when programming a mexfile with visual c++. I have selected a "Win32 DynamicLink Library" and everything works fine doing a simple dll. The problem is when including some header files to the mexproject that contains CString objects. Then the compiler says: error C2061: syntax error : identifier 'CString'
Is it not possible to use CStrings in a mexfile and in that case what to do when I'm not able to change the included header files.
Staby





The fact is the "Win32 DynamicLink" doesnt include some header files. Try to include "windows.h" in your stdafx.h and try again.
Best regards,
A. Riazi





hi All experts,
I am trying my luck here to see whether I could get any help from the experts.
I have 2 files Operation.java and Operation.class.
I can load in the Operation class into Matlab using
>> import Operation
However, when I use the command
>> [M,X,J]=inmem
I do not see the Operation class being loaded. Is there some problem?
I also need to know how do I use the Java objects from that class in Matlab. The Operation.java is as seen below:
/*Operation.java */
/*Purpose:track the properties of operation objects*/
public class Operation{
Operation prevJob = null; //previous operation in a job
Operation nextJob = null; //next operation in a job
private int job;
private int sequence;
private int machine;
private int duration;
private int est;
private int startTime;
//default constructor
public Operation(){
est = 0;
startTime = 1;
}
//constructor
public Operation(int j, int seq, int m, int d){
est = 0;
startTime = 1;
job = j;
sequence = seq;
machine = m;
duration = d;
}
//set the earilest possible start time of an operation
void setEst(int t){
est = t;
}
//sets the actual start time of an operation
void setStartTime(int t){
startTime = t;
}
//allows an opertaion to track the operation that preceeds it
void setPrevious(Operation o){
prevJob = o;
}
//allows an opertaion to track the operation that follows it
void setNext(Operation o){
nextJob = o;
}
//returns the job number of an operation
int getJob(){
return job;
}
//returns the sequence number of an operation
int getSeq(){
return sequence;
}
//returns the machine an operation is on
int getMachine(){
return machine;
}
//returns the earliest possible start time of an operation
int getEst(){
return est;
}
//returns the actual start time of an operation
int getStartTime(){
return startTime;
}
//returns the time an operation has completed its task
int getFinishTime(){
return startTime + duration;
}
//returns the amount of time an opertion nees to complete its task
int getDuration(){
return duration;
}
} //ends Operation Class







General News Suggestion Question Bug Answer Joke Praise Rant Admin Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

