📄 mexmain.cpp
字号:
// File : mexmain.cpp
// Location: ...\fgtbc3d\
// Purpose : Matlab call C++ function interface
// Author : Changjiang Yang
//
// $Revision: 0.99 $
// $Date : Mon Jul 8 18:11:31 EDT 2002 $
#include "mex.h"
#include "FastGauss.h"
/* the gateway function */
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
//plhs: double *v
//prhs: double *u, double *x, double *y, double h, int p, int K, double e
//void FastGauss(int dim, int n, double* srcs, double* sig,
// int m, double* trgs, double* wts, double tol);
//dim--dimension, n--number of nodes, K--number of centers,
//x--nodes(n), cnt--centers(K), cind--index to center(n)
{
/* check for proper number of arguments */
/* NOTE: You do not need an else statement when using mexErrMsgTxt
within an if statement, because it will never get to the else
statement if mexErrMsgTxt is executed. (mexErrMsgTxt breaks you out of
the MEX-file) */
// double *u, double *x, double *y, double h, int p, int K, double e
if(nrhs != 7)
mexErrMsgTxt("Seven inputs required.");
// double *v
if(nlhs != 1)
mexErrMsgTxt("One output required.");
//////////////////////////////////////////////////////////////
// Input arguments
//////////////////////////////////////////////////////////////
//------ the first input argument: u---------------//
int argu = 0;
/* create a pointer to the input vectors wts */
double *u = mxGetPr(prhs[argu]);
/* get the dimensions of the matrix input sources */
int dw = mxGetM(prhs[argu]); //mrows
int nw = mxGetN(prhs[argu]); //ncols
if ( dw != 1 && nw != 1)
mexErrMsgTxt("Input weights must be a vector.");
//----- the second input argument: x--------------//
argu = 1;
/* create a pointer to the input vectors srcs */
double *x = mxGetPr(prhs[argu]);
/* get the dimensions of the matrix input sources */
int ds = mxGetM(prhs[argu]); //mrows
int ns = mxGetN(prhs[argu]); //ncols
//----- the third input argument: y--------------//
argu = 2;
/* create a pointer to the input vectors trgs */
double *y = mxGetPr(prhs[argu]);
/* get the dimensions of the matrix input sources */
int dt = mxGetM(prhs[argu]); //mrows
int mt = mxGetN(prhs[argu]); //ncols
//----- the fourth input argument: h-------------//
argu = 3;
/* check to make sure the input argument is a scalar */
if( !mxIsDouble(prhs[argu]) || mxIsComplex(prhs[argu]) ||
mxGetN(prhs[argu])*mxGetM(prhs[argu])!=1 ) {
mexErrMsgTxt("Input h must be a scalar.");
}
/* get the scalar input h */
double h = mxGetScalar(prhs[argu]);
if (h <= 0.0)
mexErrMsgTxt("Input h must be a positive number.");
//----- the fifth input argument: p--------------//
argu = 4;
/* check to make sure the input argument is a scalar */
if( !mxIsDouble(prhs[argu]) || mxIsComplex(prhs[argu]) ||
mxGetN(prhs[argu])*mxGetM(prhs[argu])!=1 ) {
mexErrMsgTxt("Input p must be a scalar.");
}
/* get the scalar input p */
int p = (int) mxGetScalar(prhs[argu]);
if (p <= 0)
mexErrMsgTxt("Input p must be a positive number.");
//----- the sixth input argument: K--------------//
argu = 5;
/* check to make sure the input argument is a scalar */
if( !mxIsDouble(prhs[argu]) || mxIsComplex(prhs[argu]) ||
mxGetN(prhs[argu])*mxGetM(prhs[argu])!=1 ) {
mexErrMsgTxt("Input K must be a scalar.");
}
/* get the scalar input K */
int K = (int) mxGetScalar(prhs[argu]);
if (K <= 0)
mexErrMsgTxt("Input K must be a positive number.");
//----- the fourth input argument: e-------------//
argu = 6;
/* check to make sure the input argument is a scalar */
if( !mxIsDouble(prhs[argu]) || mxIsComplex(prhs[argu]) ||
mxGetN(prhs[argu])*mxGetM(prhs[argu])!=1 ) {
mexErrMsgTxt("Input e must be a scalar.");
}
/* get the scalar input e */
double e = mxGetScalar(prhs[argu]);
if (e <= 0.0)
mexErrMsgTxt("Input e must be a positive number.");
//////////////////////////////////////////////////////////////
// Output arguments
//////////////////////////////////////////////////////////////
/* set the output pointer to the output result(vector) */
plhs[0] = mxCreateDoubleMatrix(mt,1,mxREAL);
/* create a C pointer to a copy of the output result(vector)*/
double *v = mxGetPr(plhs[0]);
// function calls;
FastGauss* pFGT = new FastGauss(ds, u, x, ns, h, p, K, e);
pFGT->Compute_v_i(y,mt,v);
delete pFGT;
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -