exm120153_2.cpp

来自「MATLAB 6.5 从基础讲解其功能」· C++ 代码 · 共 35 行

CPP
35
字号
#include "mex.h"		//
#define MAX 1000

//-------------------------------------------------
void fill( double *pr, int *pm, int *pn, int max )
{
	int i;
	*pm = max/2;
	*pn = 1;
	for (i=0; i < (*pm); i++)
		pr[i]=i*(4*3.14159/max);
}

//-------------------------------------------------
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
	int m, n, max=MAX;
	mxArray *rhs[1], *lhs[1];
	
	rhs[0] = mxCreateDoubleMatrix(max, 1, mxREAL);		//
	
	fill(mxGetPr(rhs[0]), &m, &n, MAX);						//
	
	mxSetM(rhs[0], m);								//
	mxSetN(rhs[0], n);								//
	
	mexCallMATLAB(1, lhs, 1, rhs, "mexzzy");	//
	mexCallMATLAB(0, NULL, 1, lhs, "plot");	//

	mxDestroyArray(rhs[0]);							//
	mxDestroyArray(lhs[0]);							//

	return;
}

⌨️ 快捷键说明

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