|
|

Introduction
MATLAB is a powerful tool for engineering purposes but because of its nature, is very slow in executing functions that take a long time to execute.
For solving this problem, Mathworks provides a toolbox to compile m-files to executable ones. For this reason you can write a script and compile it to an executable with exe extension. But what about functions? Functions could be compiled to other executables called MEX-files. MEX-files in Microsoft Windows have dll extension. Therefore if you have a function like ComputePrimes that computes prime numbers and store them in a matrix, you can compile it to ComputePrimes.dll. Now MATLAB executes this function in less time. MEX-files in other operating systems have other extensions.
As you know, DLL is an abbreviation of dynamic link library and contains variables, functions and classes that are dynamically loaded by the operating system or in this situation by MATLAB. Because they are compiled, they are executed very fast.
Creating MATLAB MEX-file
To create executable files from m-files, you can use MCC. MCC is MATLAB to C/C++ compiler. It can compile m-files to executable files with exe or dll extension. For example:
Make a C translation and a MEX-file for myfun.m: mcc -x myfun
Make a C translation and a stand-alone executable for myfun.m: mcc -m myfun
Make a C++ translation and a stand-alone executable for myfun.m: mcc -p myfun
Make a C MEX wrapper file from myfun1.m and myfun2.m: mcc -W mex -L C libmatlbmx.mlib myfun1 myfun2
Make a C translation and a stand-alone executable from myfun1.m and myfun2.m (using one MCC call): mcc -m myfun1 myfun2
But there is another way to create MEX files. In this way you have full control of every function that you created and can optimize their speed, memory, size etc.
The components of a C MEX-file
The source code for a MEX-file consists of two distinct parts:
- A computational routine that contains the code for performing the computations that you want implemented in the MEX-file. Computations can be numerical computations as well as inputting and outputting data.
- A gateway routine that interfaces the computational routine with MATLAB by the entry point
mexFunction and its parameters prhs, nrhs, plhs, nlhs, where prhs is an array of right-hand input arguments, nrhs is the number of right-hand input arguments, plhs is an array of left-hand output arguments, and nlhs is the number of left-hand output arguments. The gateway calls the computational routine as a subroutine.
In the gateway routine, you can access the data in the mxArray structure and then manipulate this data in your C computational subroutine. For example, the expression mxGetPr(prhs[0]) returns a pointer of type double* to the real data in the mxArray pointed to by prhs[0]. You can then use this pointer like any other pointer of type double* in C. After calling your C computational routine from the gateway, you can set a pointer of type mxArray to the data it returns. MATLAB is then able to recognize the output from your computational routine as the output from the MEX-file.
The following C MEX cycle figure shows how inputs enter a MEX-file, what functions the gateway routine performs, and how outputs return to MATLAB.

Creating MEX-files in Visual C++
Run Visual C++, select New... from File menu. In opened dialog, select "Win32 Dynamic-Link Library". In wizard, select "A DLL that exports some symbols" and press finish. Now everything is ready for building a MEX-file!
Add following lines to main source code: #include "Matlab.h" //MATLAB API
#pragma comment(lib, "libmx.lib")
#pragma comment(lib, "libmat.lib")
#pragma comment(lib, "libmex.lib")
#pragma comment(lib, "libmatlb.lib")
Add MATLAB_MEX_FILE preprocessor to project settings (Project -> Settings -> C/C++ -> General -> Preprocessor definitions).
Create a text file and rename it to your_project.def. your_project is name of your MEX-file. your_project.def is a definition file for exporting symbols. In this situation, you must export mexFunction. Here is an example: ; mexFunction.def : Declares the module parameters for the DLL.
LIBRARY "ComputePrimes"
DESCRIPTION 'ComputePrimes Windows Dynamic Link Library'
EXPORTS
; Explicit exports can go here
mexFunction
Now you must add following compiler switch to your project (Project -> Settings -> Link -> General -> Project Options): /def:".\mexFunction.def"
Example
In this example, input argument is an integer non-complex scalar (n) and output is a vector containing first n prime numbers. Name of MEX-file is ComputePrimes. Syntax: y = ComputePrime(n)
Final Work: #include "stdafx.h"
#include "Matlab.h"
#include "mexFunction.h"
#pragma comment(lib, "libmx.lib")
#pragma comment(lib, "libmat.lib")
#pragma comment(lib, "libmex.lib")
#pragma comment(lib, "libmatlb.lib")
BOOL IsPrime(int n)
{
for (int i=2; i<=n/2; i++)
{
if (n%i==0)
return FALSE;
}
return TRUE;
}
void ComputePrimes(double* y, int n)
{
int index=0, i=2;
while (index!=n)
{
if (IsPrime(i))
{
y[index]=i;
index++;
}
i++;
}
}
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");
}
int mrows, ncols;
mrows = mxGetM(prhs[0]);
ncols = mxGetN(prhs[0]);
if (!mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) ||
!(mrows == 1 && ncols == 1))
{
mexErrMsgTxt("Input must be a noncomplex scalar integer.");
}
double x, *y;
x = mxGetScalar(prhs[0]);
plhs[0] = mxCreateDoubleMatrix(mrows , (int) x, mxREAL);
y = mxGetPr(plhs[0]);
ComputePrimes(y, (int) x);
}
Further reading
For more information about MATLAB API, refer to my articles:
Enjoy!
| You must Sign In to use this message board. |
|
| | Msgs 1 to 25 of 84 (Total in Forum: 84) (Refresh) | FirstPrevNext |
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
Can U please tell me the link from which I can download "MCC - MATLAB to C/C++ compiler" ?
Regards, Arun Kumar.A
|
| Sign In·View Thread·PermaLink | 3.43/5 (3 votes) |
|
|
|
 |
|
|
 |
|
|
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.
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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 (case-sensitive) spelling of mexFunction (for C MEX-files), or the (case-insensitive) spelling of MEXFUNCTION (for FORTRAN MEX-files). ??? Invalid MEX-file '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[i-s]-x[j-s]),disx);
for (s=1;s!=mmax+1;s++) disy = max(fabs(y[i-s]-y[j-s]),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)(N-mmax); Cxy[i] /= (double)(N-mmax); Cyz[i] /= (double)(N-mmax); Cxyz[i] /= (double)(N-mmax);
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[i-s]-x[j-s]),disx);
for (s=1;s!=mmax+1;s++) disy = max(fabs(y[i-s]-y[j-s]),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*(N-mmax)); } // end second loop over j } // end loop over i
for (i=mmax;i!=N;i++) T2 += h[i];
T2 /= (double)(N-mmax); 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=i-1; (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][i-1]!='\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][i-1]!='\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.0-k/(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[i-k];
cov[k] /= (double)(N-m-k); }
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(N-m)/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, p-value=%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.0-k/(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[i-k];
cov[k] /= (double)(N-m-k); }
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(N-m)/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, p-value=%1.5f\n",T2_TVAL,p_T2);
fcloseall(); return(0); }
sotiria
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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 (case-sensitive) spelling of mexFunction (for C MEX-files), or the (case-insensitive) spelling of MEXFUNCTION (for FORTRAN MEX-files). ??? Invalid MEX-file '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[i-s]-x[j-s]),disx); for (s=1;s!=mmax+1;s++) disy = max(fabs(y[i-s]-y[j-s]),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)(N-mmax); Cxy[i] /= (double)(N-mmax); Cyz[i] /= (double)(N-mmax); Cxyz[i] /= (double)(N-mmax); 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[i-s]-x[j-s]),disx); for (s=1;s!=mmax+1;s++) disy = max(fabs(y[i-s]-y[j-s]),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*(N-mmax)); } // end second loop over j } // end loop over i for (i=mmax;i!=N;i++) T2 += h[i]; T2 /= (double)(N-mmax); 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=i-1; (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][i-1]!='\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][i-1]!='\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.0-k/(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[i-k]; cov[k] /= (double)(N-m-k); } 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(N-m)/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, p-value=%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.0-k/(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[i-k]; cov[k] /= (double)(N-m-k); } 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(N-m)/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, p-value=%1.5f\n",T2_TVAL,p_T2); fcloseall(); return(0); }
sotiria
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
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 32-bit Windows MEX-files was changed from ".dll" to ".mexw32" in MATLAB 7.1 (R14SP3). The generated MEX-file will not be found by MATLAB versions prior to 7.1. Use the -output option with the ".dll" file extension to generate a MEX-file that can be called in previous versions. For more information see: MATLAB 7.1 Release Notes, New File Extension for MEX-Files 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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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: ibm-5348_P100-1997
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 MEX-file was running. If the MEX-file is not an official MathWorks function, please examine its source code for errors. Please consult the External Interfaces Guide for information on debugging MEX-files.
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
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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 (ITU-R 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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, I created a new S-function 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
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
Hi, Basically you must include the DLL header file to your code and also import its library (*.lib).
Best regards, A. Riazi
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks for your reply, but how this can be reached? to import the dll files with the c -file created?
Thanks again
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
| | |