⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mycalc.c

📁 《精通matlab7》“mastering matlab 7”的代码。
💻 C
字号:
/* * mycalc.c - calculates x^2 - x + 1/x for each element of an array. * *   MATLAB usage:   p = mycalc(n) * *   Mastering MATLAB 7 C MEX Example 2:  *       single 2-D real numeric array input,  *       single array output. */#include "mex.h"/* This is the original subroutine that performs the calculation. */static void mycalc( double p[], double n[], int r, int c){    int i;    for (i = 0; i < r*c; i++)        p[i] = n[i]*n[i]-n[i]+1.0/n[i];}/* This is the interface to MATLAB data types and arguments. */void mexFunction( int nlhs,       mxArray *plhs[], 		          int nrhs, const mxArray *prhs[] ){     double *p, *n;     int  r, c;         /* Do some error checking. */    if (nrhs != 1)          mexErrMsgTxt("One input argument required.");     else if (nlhs > 1)       mexErrMsgTxt("Too many output arguments.");     else if (!mxIsNumeric(prhs[0]))      mexErrMsgTxt("Input must be numeric.");     else if (mxIsComplex(prhs[0]))      mexErrMsgTxt("Input must be real.");     else if (mxGetNumberOfDimensions(prhs[0]) > 2)      mexErrMsgTxt("N-Dimensional arrays are not supported.");         /* Get the input array dimensions. */    r = mxGetM(prhs[0]);     c = mxGetN(prhs[0]);    /* Create a matrix for the return argument */     plhs[0] = mxCreateDoubleMatrix(r, c, mxREAL);         /* Assign pointers to the parameters */     p = mxGetPr(plhs[0]);    n = mxGetPr(prhs[0]);    /* Do the actual calculation in a subroutine. */    mycalc(p, n, r, c); }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -