📄 meanfunction.c
字号:
/*
* MATLAB Compiler: 3.0
* Date: Wed Dec 31 16:59:42 2003
* 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" "-L" "C" "-W"
* "lib:MeanFunctionLib" "-T" "link:lib" "MeanFunction.m" "libmmfile.mlib"
*/
#include "meanfunction.h"
#include "libmatlbm.h"
static mxArray * _mxarray0_;
static mxArray * _mxarray1_;
void InitializeModule_meanfunction(void) {
_mxarray0_ = mclInitializeDouble(0.0);
_mxarray1_ = mclInitializeDoubleVector(0, 0, (double *)NULL);
}
void TerminateModule_meanfunction(void) {
mxDestroyArray(_mxarray1_);
mxDestroyArray(_mxarray0_);
}
static mxArray * Mmeanfunction(int nargout_, mxArray * x);
_mexLocalFunctionTable _local_function_table_meanfunction
= { 0, (mexFunctionTableEntry *)NULL };
/*
* The function "mlfMeanfunction" contains the normal interface for the
* "meanfunction" M-function from file "g:\matlab\work\meanfunction.m" (lines
* 1-8). This function processes any input arguments and passes them to the
* implementation version of the function, appearing above.
*/
mxArray * mlfMeanfunction(mxArray * x) {
int nargout = 1;
mxArray * y = NULL;
mlfEnterNewContext(0, 1, x);
y = Mmeanfunction(nargout, x);
mlfRestorePreviousContext(0, 1, x);
return mlfReturnValue(y);
}
/*
* The function "mlxMeanfunction" contains the feval interface for the
* "meanfunction" M-function from file "g:\matlab\work\meanfunction.m" (lines
* 1-8). The feval function calls the implementation version of meanfunction
* through this function. This function processes any input arguments and
* passes them to the implementation version of the function, appearing above.
*/
void mlxMeanfunction(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: meanfunction Line: 1 Column"
": 1 The function \"meanfunction\" was called with"
" more than the declared number of outputs (1)."),
NULL);
}
if (nrhs > 1) {
mlfError(
mxCreateString(
"Run-time Error: File: meanfunction Line: 1 Column"
": 1 The function \"meanfunction\" was called with"
" more 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] = Mmeanfunction(nlhs, mprhs[0]);
mlfRestorePreviousContext(0, 1, mprhs[0]);
plhs[0] = mplhs[0];
}
/*
* The function "Mmeanfunction" is the implementation version of the
* "meanfunction" M-function from file "g:\matlab\work\meanfunction.m" (lines
* 1-8). 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=MeanFunction(x)
*/
static mxArray * Mmeanfunction(int nargout_, mxArray * x) {
mexLocalFunctionTable save_local_function_table_
= mclSetCurrentLocalFunctionTable(&_local_function_table_meanfunction);
mxArray * y = NULL;
mxArray * i = NULL;
mxArray * k = NULL;
mxArray * n = NULL;
mxArray * m = NULL;
mclCopyArray(&x);
/*
* [m,n]=size(x);
*/
mlfSize(mlfVarargout(&m, &n, NULL), mclVa(x, "x"), NULL);
/*
* k=0;
*/
mlfAssign(&k, _mxarray0_);
/*
* for i=1:n
*/
{
int v_ = mclForIntStart(1);
int e_ = mclForIntEnd(mclVv(n, "n"));
if (v_ > e_) {
mlfAssign(&i, _mxarray1_);
} else {
/*
* k=k+x(i);
* end
*/
for (; ; ) {
mlfAssign(
&k,
mclPlus(mclVv(k, "k"), mclIntArrayRef1(mclVa(x, "x"), v_)));
if (v_ == e_) {
break;
}
++v_;
}
mlfAssign(&i, mlfScalar(v_));
}
}
/*
* y=k/n;
*/
mlfAssign(&y, mclMrdivide(mclVv(k, "k"), mclVv(n, "n")));
mclValidateOutput(y, 1, nargout_, "y", "meanfunction");
mxDestroyArray(m);
mxDestroyArray(n);
mxDestroyArray(k);
mxDestroyArray(i);
mxDestroyArray(x);
mclSetCurrentLocalFunctionTable(save_local_function_table_);
return y;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -