MATLAB REAL-TIME WORKSHOP 7 - TARGET LANGUAGE COMPILER Manual do Utilizador Página 75

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 408
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 74
Examples of C MEX-Files
2-15
void xtimesy(double x, double *y, double *z, int m, int n)
{
int i,j,count = 0;
for(i = 0; i < n; i++) {
for(j = 0; j < m; j++) {
*(z+count) = x * *(y+count);
count++;
}
}
}
/* The gateway routine */
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
double *y,*z;
double x;
int status,mrows,ncols;
/* Check for proper number of arguments. */
/* NOTE: You do not need an else statement when using
mexErrMsgTxt within an if statement. It will never
get to the else statement if mexErrMsgTxt is executed.
(mexErrMsgTxt breaks you out of the MEX-file.)
*/
if(nrhs != 2)
mexErrMsgTxt("Two inputs required.");
if(nlhs != 1)
mexErrMsgTxt("One output required.");
/* Check to make sure the first input argument is a scalar. */
if(!mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) ||
mxGetN(prhs[0])*mxGetM(prhs[0]) != 1 ) {
mexErrMsgTxt("Input x must be a scalar.");
}
/* Get the scalar input x. */
x = mxGetScalar(prhs[0]);
Vista de página 74
1 2 ... 70 71 72 73 74 75 76 77 78 79 80 ... 407 408

Comentários a estes Manuais

Sem comentários