示例#1
0
/* 此函式為和 MATLAB 溝通的主要函式 */
void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[] ) {
    double *xr, *xi, *yr, *yi;
    int length = mxGetM(IN)*mxGetN(IN);

    /* 檢查輸出和輸入變數個數是否都是1,其中		  */
    /* nrhs = no. of right-hand-side arguments(輸入變數個數)*/
    /* nlhs = no. of  left-hand-side arguments(輸出變數個數)*/
    if(nrhs!=1)	/* 檢查輸入變數個數是否是1 */
        mexErrMsgTxt("One input required.");
    if(nlhs>1)	/* 檢查輸出變數個數是否是1 */
        mexErrMsgTxt("Too many output arguments");

    /* 檢查輸入變數是否合格 */
    if(!mxIsDouble(IN))		/* 檢查輸入變數是否為 double */
        mexErrMsgTxt("Input must be a double.");

    /* 配置記憶體給輸出變數 */
    OUT = mxCreateDoubleMatrix(mxGetM(IN), mxGetN(IN), mxCOMPLEX);

    /* 取得輸入和輸出變數的實部指標 */
    xr = mxGetPr(IN);
    yr = mxGetPr(OUT);
    /* 取得輸入和輸出變數的虛部指標 */
    if (mxIsComplex(IN)) {
        xi = mxGetPi(IN);
        yi = mxGetPi(OUT);
    }

    /* 執行實際的運算:將輸入向量的實部乘以2 */
    timestwo(yr, xr, length);
    /* 執行實際的運算:將輸入向量的虛部乘以2 */
    if (mxIsComplex(IN))
        timestwo(yi, xi, length);
}
示例#2
0
void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[] )
{
  double *x,*y;
  mwSize mrows,ncols;
  
  /* Check for proper number of arguments. */
  if(nrhs!=1) {
    mexErrMsgTxt("One input required.");
  } else if(nlhs>1) {
    mexErrMsgTxt("Too many output arguments");
  }
  
  /* The input must be a noncomplex scalar double.*/
  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 double.");
  }
  
  /* Create matrix for the return argument. */
  plhs[0] = mxCreateDoubleMatrix(mrows,ncols, mxREAL);
  
  /* Assign pointers to each input and output. */
  x = mxGetPr(prhs[0]);
  y = mxGetPr(plhs[0]);
  
  /* Call the timestwo subroutine. */
  timestwo(y,x);
}
示例#3
0
/* 此函式為和 MATLAB 溝通的主要函式 */
void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[] ) {
	double *x, *y;
	int    no_rows, no_cols;
  
	/* 檢查輸出和輸入變數個數是否都是1,其中		  */
	/* nrhs = no. of right-hand-side arguments(輸入變數個數)*/
	/* nlhs = no. of  left-hand-side arguments(輸出變數個數)*/
	if(nrhs!=1)	/* 檢查輸入變數個數是否是1 */
		mexErrMsgTxt("One input required.");
	if(nlhs>1)	/* 檢查輸出變數個數是否是1 */
		mexErrMsgTxt("Too many output arguments");
  
	/* 檢查輸入變數是否合格 */
	no_rows = mxGetM(IN);	/* 橫列維度 */
	no_cols = mxGetN(IN);	/* 直行維度 */
	if(!(no_rows==1 && no_cols==1))	/* 檢查輸入變數是否為純量 */
		mexErrMsgTxt("Input must be a scalar.");
	if(mxIsComplex(IN))		/* 檢查輸入變數是否為實數 */
		mexErrMsgTxt("Input must be noncomplex.");
	if(!mxIsDouble(IN))		/* 檢查輸入變數是否為 double */
		mexErrMsgTxt("Input must be a double.");
  
	/* 配置記憶體給輸出變數 */
	OUT = mxCreateDoubleMatrix(no_rows, no_cols, mxREAL);
  
	/* 取得輸入和輸出變數的指標 */
	x = mxGetPr(IN);
	y = mxGetPr(OUT);
  
	/* 執行實際的運算:將輸入純量乘以2 */
	timestwo(y, x);
}
示例#4
0
void f()
{
  int i = 1252;
  printf("i:%d\n", i);
  printf("times_two(&i)=%d\n", times_two(&i));
  printf("après times_two, i:%d\n", i);
  printf("timestwo(&i)=%d\n", timestwo(&i));
  printf("après timestwo, i:%d\n", i);
}
示例#5
0
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
	double *x,*y;
	int mrows,ncols;
	mrows=mxGetM(prhs[0]);
	ncols=mxGetN(prhs[0]);
	plhs[0]=mxCreateDoubleMatrix(mrows,ncols,mxREAL);
	x=mxGetPr(prhs[0]);
	y=mxGetPr(plhs[0]);
	timestwo(y,x);
}
示例#6
0
/** do setup exponentially */
static void
dosetup(struct timehist* hist)
{
	struct timeval last;
	size_t i;
	memset(&last, 0, sizeof(last));
	for(i=0; i<hist->num; i++) {
		hist->buckets[i].lower = last;
		timestwo(&last);
		hist->buckets[i].upper = last;
		hist->buckets[i].count = 0;
	}
}