📄 peaks.cpp
字号:
//
// MATLAB Compiler: 3.0
// Date: Sun Dec 14 21:22:13 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" "-B" "sglcpp" "-p" "-W"
// "main" "-L" "Cpp" "-t" "-T" "link:exe" "-h" "libmmfile.mlib" "-W" "mainhg"
// "libmwsglm.mlib" "test.m"
//
#include "peaks.hpp"
#include "libmatlbm.hpp"
#include "libmmfile.hpp"
#include "surf.hpp"
#include "title.hpp"
#include "xlabel.hpp"
#include "ylabel.hpp"
static mwArray _mxarray0_ = mclInitializeDouble(.125);
static mwArray _mxarray1_ = mclInitializeDouble(-3.0);
static mwArray _mxarray2_ = mclInitializeDouble(3.0);
static mwArray _mxarray3_ = mclInitializeDouble(6.0);
static mwArray _mxarray4_ = mclInitializeDouble(1.0);
static mwArray _mxarray5_ = mclInitializeDouble(2.0);
static mwArray _mxarray6_ = mclInitializeDouble(10.0);
static mwArray _mxarray7_ = mclInitializeDouble(5.0);
static mwArray _mxarray8_ = mclInitializeDouble(.3333333333333333);
static mxChar _array10_[1] = { ' ' };
static mwArray _mxarray9_ = mclInitializeString(1, _array10_);
static mxChar _array12_[45] = { 'z', ' ', '=', ' ', ' ', '3', '*', '(', '1',
'-', 'x', ')', '.', '^', '2', '.', '*', 'e',
'x', 'p', '(', '-', '(', 'x', '.', '^', '2',
')', ' ', '-', ' ', '(', 'y', '+', '1', ')',
'.', '^', '2', ')', ' ', '.', '.', '.', ' ' };
static mwArray _mxarray11_ = mclInitializeString(45, _array12_);
static mxChar _array14_[49] = { ' ', ' ', ' ', '-', ' ', '1', '0', '*', '(',
'x', '/', '5', ' ', '-', ' ', 'x', '.', '^',
'3', ' ', '-', ' ', 'y', '.', '^', '5', ')',
'.', '*', 'e', 'x', 'p', '(', '-', 'x', '.',
'^', '2', '-', 'y', '.', '^', '2', ')', ' ',
'.', '.', '.', ' ' };
static mwArray _mxarray13_ = mclInitializeString(49, _array14_);
static mxChar _array16_[31] = { ' ', ' ', ' ', '-', ' ', '1', '/', '3',
'*', 'e', 'x', 'p', '(', '-', '(', 'x',
'+', '1', ')', '.', '^', '2', ' ', '-',
' ', 'y', '.', '^', '2', ')', ' ' };
static mwArray _mxarray15_ = mclInitializeString(31, _array16_);
static mxChar _array18_[1] = { 'x' };
static mwArray _mxarray17_ = mclInitializeString(1, _array18_);
static mxChar _array20_[1] = { 'y' };
static mwArray _mxarray19_ = mclInitializeString(1, _array20_);
static mxChar _array22_[5] = { 'P', 'e', 'a', 'k', 's' };
static mwArray _mxarray21_ = mclInitializeString(5, _array22_);
void InitializeModule_peaks() {
}
void TerminateModule_peaks() {
}
static mwArray Mpeaks(mwArray * y,
mwArray * z,
int nargout_,
mwArray arg1,
mwArray arg2);
_mexLocalFunctionTable _local_function_table_peaks
= { 0, (mexFunctionTableEntry *)NULL };
//
// The function "Npeaks" contains the nargout interface for the "peaks"
// M-function from file "e:\matlab6p5\toolbox\matlab\demos\peaks.m" (lines
// 1-77). This interface is only produced if the M-function uses the special
// variable "nargout". The nargout interface allows the number of requested
// outputs to be specified via the nargout argument, as opposed to the normal
// interface which dynamically calculates the number of outputs based on the
// number of non-NULL inputs it receives. This function processes any input
// arguments and passes them to the implementation version of the function,
// appearing above.
//
mwArray Npeaks(int nargout,
mwArray * y,
mwArray * z,
mwArray arg1,
mwArray arg2) {
mwArray xz = mwArray::UNDEFINED;
mwArray y__ = mwArray::UNDEFINED;
mwArray z__ = mwArray::UNDEFINED;
xz = Mpeaks(&y__, &z__, nargout, arg1, arg2);
if (y != NULL) {
*y = y__;
}
if (z != NULL) {
*z = z__;
}
return xz;
}
//
// The function "peaks" contains the normal interface for the "peaks"
// M-function from file "e:\matlab6p5\toolbox\matlab\demos\peaks.m" (lines
// 1-77). This function processes any input arguments and passes them to the
// implementation version of the function, appearing above.
//
mwArray peaks(mwArray * y, mwArray * z, mwArray arg1, mwArray arg2) {
int nargout = 1;
mwArray xz = mwArray::UNDEFINED;
mwArray y__ = mwArray::UNDEFINED;
mwArray z__ = mwArray::UNDEFINED;
if (y != NULL) {
++nargout;
}
if (z != NULL) {
++nargout;
}
xz = Mpeaks(&y__, &z__, nargout, arg1, arg2);
if (y != NULL) {
*y = y__;
}
if (z != NULL) {
*z = z__;
}
return xz;
}
//
// The function "Vpeaks" contains the void interface for the "peaks" M-function
// from file "e:\matlab6p5\toolbox\matlab\demos\peaks.m" (lines 1-77). The void
// interface is only produced if the M-function uses the special variable
// "nargout", and has at least one output. The void interface function
// specifies zero output arguments to the implementation version of the
// function, and in the event that the implementation version still returns an
// output (which, in MATLAB, would be assigned to the "ans" variable), it
// deallocates the output. This function processes any input arguments and
// passes them to the implementation version of the function, appearing above.
//
void Vpeaks(mwArray arg1, mwArray arg2) {
mwArray xz = mwArray::UNDEFINED;
mwArray y = mwArray::UNDEFINED;
mwArray z = mwArray::UNDEFINED;
xz = Mpeaks(&y, &z, 0, arg1, arg2);
}
//
// The function "mlxPeaks" contains the feval interface for the "peaks"
// M-function from file "e:\matlab6p5\toolbox\matlab\demos\peaks.m" (lines
// 1-77). The feval function calls the implementation version of peaks through
// this function. This function processes any input arguments and passes them
// to the implementation version of the function, appearing above.
//
void mlxPeaks(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
MW_BEGIN_MLX();
{
mwArray mprhs[2];
mwArray mplhs[3];
int i;
mclCppUndefineArrays(3, mplhs);
if (nlhs > 3) {
error(
mwVarargin(
mwArray(
"Run-time Error: File: peaks Line: 1 Column: 1"
" The function \"peaks\" was called with more "
"than the declared number of outputs (3).")));
}
if (nrhs > 2) {
error(
mwVarargin(
mwArray(
"Run-time Error: File: peaks Line: 1 Column: 1"
" The function \"peaks\" was called with more "
"than the declared number of inputs (2).")));
}
for (i = 0; i < 2 && i < nrhs; ++i) {
mprhs[i] = mwArray(prhs[i], 0);
}
for (; i < 2; ++i) {
mprhs[i].MakeDIN();
}
mplhs[0] = Mpeaks(&mplhs[1], &mplhs[2], nlhs, mprhs[0], mprhs[1]);
plhs[0] = mplhs[0].FreezeData();
for (i = 1; i < 3 && i < nlhs; ++i) {
plhs[i] = mplhs[i].FreezeData();
}
}
MW_END_MLX();
}
//
// The function "Mpeaks" is the implementation version of the "peaks"
// M-function from file "e:\matlab6p5\toolbox\matlab\demos\peaks.m" (lines
// 1-77). 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 [xz,y,z] = peaks(arg1,arg2);
//
static mwArray Mpeaks(mwArray * y,
mwArray * z,
int nargout_,
mwArray arg1,
mwArray arg2) {
mwLocalFunctionTable save_local_function_table_
= &_local_function_table_peaks;
int nargin_ = nargin(2, mwVarargin(arg1, arg2));
mwArray xz = mwArray::UNDEFINED;
mwArray ans = mwArray::UNDEFINED;
mwArray x = mwArray::UNDEFINED;
mwArray dx = mwArray::UNDEFINED;
//
// %PEAKS A sample function of two variables.
// % PEAKS is a function of two variables, obtained by translating and
// % scaling Gaussian distributions, which is useful for demonstrating
// % MESH, SURF, PCOLOR, CONTOUR, etc.
// % There are several variants of the calling sequence:
// %
// % Z = PEAKS;
// % Z = PEAKS(N);
// % Z = PEAKS(V);
// % Z = PEAKS(X,Y);
// %
// % PEAKS;
// % PEAKS(N);
// % PEAKS(V);
// % PEAKS(X,Y);
// %
// % [X,Y,Z] = PEAKS;
// % [X,Y,Z] = PEAKS(N);
// % [X,Y,Z] = PEAKS(V);
// %
// % The first variant produces a 49-by-49 matrix.
// % The second variant produces an N-by-N matrix.
// % The third variant produces an N-by-N matrix where N = length(V).
// % The fourth variant evaluates the function at the given X and Y,
// % which must be the same size. The resulting Z is also that size.
// %
// % The next four variants, with no output arguments, do a SURF
// % plot of the result.
// %
// % The last three variants also produce two matrices, X and Y, for
// % use in commands such as PCOLOR(X,Y,Z) or SURF(X,Y,Z,DEL2(Z)).
// %
// % If not given as input, the underlying matrices X and Y are
// % [X,Y] = MESHGRID(V,V)
// % where V is a given vector, or V is a vector of length N with
// % elements equally spaced from -3 to 3. If no input argument is
// % given, the default N is 49.
//
// % CBM, 2-1-92, 8-11-92, 4-30-94.
// % Copyright 1984-2002 The MathWorks, Inc.
// % $Revision: 5.10 $ $Date: 2002/04/08 20:04:50 $
//
// if nargin == 0
//
if (nargin_ == 0) {
//
// dx = 1/8;
//
dx = _mxarray0_;
//
// [x,y] = meshgrid(-3:dx:3);
//
x
= Nmeshgrid(2, y, NULL, colon(_mxarray1_, mwVv(dx, "dx"), _mxarray2_));
//
// elseif nargin == 1
//
} else if (nargin_ == 1) {
//
// if length(arg1) == 1
//
if (mclLengthInt(mwVa(arg1, "arg1")) == 1) {
//
// [x,y] = meshgrid(-3:6/(arg1-1):3);
//
x
= Nmeshgrid(
2,
y,
NULL,
colon(
_mxarray1_,
_mxarray3_ / (mwVa(arg1, "arg1") - _mxarray4_),
_mxarray2_));
//
// else
//
} else {
//
// [x,y] = meshgrid(arg1,arg1);
//
x = Nmeshgrid(2, y, NULL, mwVa(arg1, "arg1"), mwVa(arg1, "arg1"));
//
// end
//
}
//
// else
//
} else {
//
// x = arg1; y = arg2;
//
x = mwVa(arg1, "arg1");
*y = mwVa(arg2, "arg2");
//
// end
//
}
//
//
// z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...
//
*z
= times(
_mxarray2_ * power(_mxarray4_ - mwVv(x, "x"), _mxarray5_),
exp(
- power(mwVv(x, "x"), _mxarray5_)
- power(mwVv(*y, "y") + _mxarray4_, _mxarray5_)))
- times(
_mxarray6_
* (mwVv(x, "x") / _mxarray7_ - power(mwVv(x, "x"), _mxarray2_)
- power(mwVv(*y, "y"), _mxarray7_)),
exp(
- power(mwVv(x, "x"), _mxarray5_)
- power(mwVv(*y, "y"), _mxarray5_)))
- _mxarray8_
* exp(
- power(mwVv(x, "x") + _mxarray4_, _mxarray5_)
- power(mwVv(*y, "y"), _mxarray5_));
//
// - 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ...
// - 1/3*exp(-(x+1).^2 - y.^2);
//
// if nargout > 1
//
if (nargout_ > 1) {
//
// xz = x;
//
xz = mwVv(x, "x");
//
// elseif nargout == 1
//
} else if (nargout_ == 1) {
//
// xz = z;
//
xz = mwVv(*z, "z");
//
// else
//
} else {
//
// % Self demonstration
// disp(' ')
//
disp(_mxarray9_);
//
// disp('z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ... ')
//
disp(_mxarray11_);
//
// disp(' - 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ... ')
//
disp(_mxarray13_);
//
// disp(' - 1/3*exp(-(x+1).^2 - y.^2) ')
//
disp(_mxarray15_);
//
// disp(' ')
//
disp(_mxarray9_);
//
// surf(x,y,z)
//
ans.EqPrintAns(
Nsurf(0, mwVarargin(mwVv(x, "x"), mwVv(*y, "y"), mwVv(*z, "z"))));
//
// axis([min(min(x)) max(max(x)) min(min(y)) max(max(y)) ...
//
ans.EqPrintAns(
Naxis(
0,
NULL,
NULL,
mwVarargin(
horzcat(
mwVarargin(
min(min(mwVv(x, "x"))),
max(max(mwVv(x, "x"))),
min(min(mwVv(*y, "y"))),
max(max(mwVv(*y, "y"))),
min(min(mwVv(*z, "z"))),
max(max(mwVv(*z, "z"))))))));
//
// min(min(z)) max(max(z))])
// xlabel('x'), ylabel('y'), title('Peaks')
//
ans.EqPrintAns(Nxlabel(0, _mxarray17_, mwVarargin()));
ans.EqPrintAns(Nylabel(0, _mxarray19_, mwVarargin()));
ans.EqPrintAns(Ntitle(0, _mxarray21_, mwVarargin()));
//
// end
//
}
mwValidateOutput(xz, 1, nargout_, "xz", "peaks");
mwValidateOutput(*y, 2, nargout_, "y", "peaks");
mwValidateOutput(*z, 3, nargout_, "z", "peaks");
return xz;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -