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

📄 sincplot.c

📁 本软件提供了VC++中调用Matlab.m函数编译后的动态链接库.Matlab的数值处理能力很强,用VC++调用Matlab函数可以解决很多问题
💻 C
字号:
/*
 * MATLAB Compiler: 3.0
 * Date: Wed Dec 22 21:10:08 2004
 * Arguments: "-B" "macro_default" "-O" "all" "-O" "fold_scalar_mxarrays:on"
 * "-O" "fold_non_scalar_mxarrays:on" "-O" "optimize_integer_for_loops:on" "-O"
 * "array_indexing:on" "-O" "optimize_conditionals:on" "-t" "-W"
 * "libhg:libsincplot" "-L" "C" "-T" "link:lib" "sincplot.m" 
 */
#include "sincplot.h"
#include "libmatlbm.h"
static mxArray * _mxarray0_;
static mxArray * _mxarray1_;
static mxArray * _mxarray2_;

void InitializeModule_sincplot(void) {
    _mxarray0_ = mclInitializeDouble(.01);
    _mxarray1_ = mclInitializeDouble(3.141592653589793);
    _mxarray2_ = mclInitializeDouble(-.01);
}

void TerminateModule_sincplot(void) {
    mxDestroyArray(_mxarray2_);
    mxDestroyArray(_mxarray1_);
    mxDestroyArray(_mxarray0_);
}

static mxArray * Msincplot(int nargout_, mxArray * n);

_mexLocalFunctionTable _local_function_table_sincplot
  = { 0, (mexFunctionTableEntry *)NULL };

/*
 * The function "mlfSincplot" contains the normal interface for the "sincplot"
 * M-function from file "e:\matlab 书籍代码\第四章\vc中调用matlab
 * .m函数编译后的动态链接库\m\sincplot.m" (lines 1-9). This function processes
 * any input arguments and passes them to the implementation version of the
 * function, appearing above.
 */
mxArray * mlfSincplot(mxArray * n) {
    int nargout = 1;
    mxArray * y = NULL;
    mlfEnterNewContext(0, 1, n);
    y = Msincplot(nargout, n);
    mlfRestorePreviousContext(0, 1, n);
    return mlfReturnValue(y);
}

/*
 * The function "mlxSincplot" contains the feval interface for the "sincplot"
 * M-function from file "e:\matlab 书籍代码\第四章\vc中调用matlab
 * .m函数编译后的动态链接库\m\sincplot.m" (lines 1-9). The feval function calls
 * the implementation version of sincplot through this function. This function
 * processes any input arguments and passes them to the implementation version
 * of the function, appearing above.
 */
void mlxSincplot(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
    mxArray * mprhs[1];
    mxArray * mplhs[1];
    int i;
    if (nlhs > 1) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: sincplot Line: 1 Column:"
            " 1 The function \"sincplot\" was called with m"
            "ore than the declared number of outputs (1)."),
          NULL);
    }
    if (nrhs > 1) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: sincplot Line: 1 Column:"
            " 1 The function \"sincplot\" was called with m"
            "ore than the declared number of inputs (1)."),
          NULL);
    }
    for (i = 0; i < 1; ++i) {
        mplhs[i] = NULL;
    }
    for (i = 0; i < 1 && i < nrhs; ++i) {
        mprhs[i] = prhs[i];
    }
    for (; i < 1; ++i) {
        mprhs[i] = NULL;
    }
    mlfEnterNewContext(0, 1, mprhs[0]);
    mplhs[0] = Msincplot(nlhs, mprhs[0]);
    mlfRestorePreviousContext(0, 1, mprhs[0]);
    plhs[0] = mplhs[0];
}

/*
 * The function "Msincplot" is the implementation version of the "sincplot"
 * M-function from file "e:\matlab 书籍代码\第四章\vc中调用matlab
 * .m函数编译后的动态链接库\m\sincplot.m" (lines 1-9). It contains the actual
 * compiled code for that M-function. It is a static function and must only be
 * called from one of the interface functions, appearing below.
 */
/*
 * function [y]=sincplot(n)
 */
static mxArray * Msincplot(int nargout_, mxArray * n) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(&_local_function_table_sincplot);
    mxArray * y = NULL;
    mxArray * ans = NULL;
    mxArray * y2 = NULL;
    mxArray * x2 = NULL;
    mxArray * y1 = NULL;
    mxArray * x1 = NULL;
    mclCopyArray(&n);
    /*
     * %function []=sincplot()
     * x1=0.01:0.01:n*pi;
     */
    mlfAssign(
      &x1,
      mlfColon(_mxarray0_, _mxarray0_, mclMtimes(mclVa(n, "n"), _mxarray1_)));
    /*
     * y1=sin(x1)./x1;
     */
    mlfAssign(&y1, mclRdivide(mlfSin(mclVv(x1, "x1")), mclVv(x1, "x1")));
    /*
     * x2=-n*pi:0.01:-0.01;
     */
    mlfAssign(
      &x2,
      mlfColon(
        mclMtimes(mclUminus(mclVa(n, "n")), _mxarray1_),
        _mxarray0_,
        _mxarray2_));
    /*
     * y2=sin(x2)./x2;
     */
    mlfAssign(&y2, mclRdivide(mlfSin(mclVv(x2, "x2")), mclVv(x2, "x2")));
    /*
     * y=[y2 y1];
     */
    mlfAssign(&y, mlfHorzcat(mclVv(y2, "y2"), mclVv(y1, "y1"), NULL));
    /*
     * plot([x2 x1],y);
     */
    mclAssignAns(
      &ans,
      mlfNPlot(
        0,
        mlfHorzcat(mclVv(x2, "x2"), mclVv(x1, "x1"), NULL),
        mclVv(y, "y"),
        NULL));
    mclValidateOutput(y, 1, nargout_, "y", "sincplot");
    mxDestroyArray(x1);
    mxDestroyArray(y1);
    mxDestroyArray(x2);
    mxDestroyArray(y2);
    mxDestroyArray(ans);
    mxDestroyArray(n);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
    return y;
}

⌨️ 快捷键说明

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