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

📄 gjfcz.c

📁 介绍了如何将m文件转换成VC可调用的dll文件,在这章中介绍如何利用编译器将m文件转换成对应的CC++文件,并在VC中调用
💻 C
字号:
/*
 * MATLAB Compiler: 3.0
 * Date: Thu Nov 17 16:16:01 2005
 * 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" "-m" "-W" "main" "-L"
 * "C" "-t" "-T" "link:exe" "-h" "libmmfile.mlib" "gjfcz.m" 
 */
#include "gjfcz.h"
#include "libmatlbm.h"

void InitializeModule_gjfcz(void) {
}

void TerminateModule_gjfcz(void) {
}

static mxArray * Mgjfcz(int nargout_, mxArray * A, mxArray * b);

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

/*
 * The function "mlfGjfcz" contains the normal interface for the "gjfcz"
 * M-function from file "d:\matlab6\work\gjfcz.m" (lines 1-4). This function
 * processes any input arguments and passes them to the implementation version
 * of the function, appearing above.
 */
mxArray * mlfGjfcz(mxArray * A, mxArray * b) {
    int nargout = 1;
    mxArray * x = NULL;
    mlfEnterNewContext(0, 2, A, b);
    x = Mgjfcz(nargout, A, b);
    mlfRestorePreviousContext(0, 2, A, b);
    return mlfReturnValue(x);
}

/*
 * The function "mlxGjfcz" contains the feval interface for the "gjfcz"
 * M-function from file "d:\matlab6\work\gjfcz.m" (lines 1-4). The feval
 * function calls the implementation version of gjfcz through this function.
 * This function processes any input arguments and passes them to the
 * implementation version of the function, appearing above.
 */
void mlxGjfcz(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
    mxArray * mprhs[2];
    mxArray * mplhs[1];
    int i;
    if (nlhs > 1) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: gjfcz Line: 1 Column: 1 The function \"gjfcz"
            "\" was called with more than the declared number of outputs (1)."),
          NULL);
    }
    if (nrhs > 2) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: gjfcz Line: 1 Column: 1 The function \"gjfcz"
            "\" was called with more than the declared number of inputs (2)."),
          NULL);
    }
    for (i = 0; i < 1; ++i) {
        mplhs[i] = NULL;
    }
    for (i = 0; i < 2 && i < nrhs; ++i) {
        mprhs[i] = prhs[i];
    }
    for (; i < 2; ++i) {
        mprhs[i] = NULL;
    }
    mlfEnterNewContext(0, 2, mprhs[0], mprhs[1]);
    mplhs[0] = Mgjfcz(nlhs, mprhs[0], mprhs[1]);
    mlfRestorePreviousContext(0, 2, mprhs[0], mprhs[1]);
    plhs[0] = mplhs[0];
}

/*
 * The function "Mgjfcz" is the implementation version of the "gjfcz"
 * M-function from file "d:\matlab6\work\gjfcz.m" (lines 1-4). 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 [x]=gjfcz(A,b)
 */
static mxArray * Mgjfcz(int nargout_, mxArray * A, mxArray * b) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(&_local_function_table_gjfcz);
    mxArray * x = NULL;
    mclCopyArray(&A);
    mclCopyArray(&b);
    /*
     * %A=[-1.5 1 2; 4 2 3 ; -3 2 8]
     * %b=[3;5;6]
     * x=A\b
     */
    mlfAssign(&x, mlfMldivide(mclVa(A, "A"), mclVa(b, "b")));
    mclPrintArray(mclVv(x, "x"), "x");
    mclValidateOutput(x, 1, nargout_, "x", "gjfcz");
    mxDestroyArray(b);
    mxDestroyArray(A);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
    return x;
}

⌨️ 快捷键说明

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