MATLAB REAL-TIME WORKSHOP 7 - TARGET LANGUAGE COMPILER Manual de usuario Pagina 81

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 408
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 80
Examples of C MEX-Files
2-21
Handling Complex Data
Complex data from MATLAB is separated into real and imaginary parts.
MATLAB’s API provides two functions,
mxGetPr and mxGetPi, that return
pointers (of type
double *) to the real and imaginary parts of your data.
This example takes two complex row vectors and convolves them.
/* $Revision: 1.8 $ */
/*=========================================================
* convec.c
* Example for illustrating how to pass complex data
* from MATLAB to C and back again
*
* Convolves two complex input vectors.
*
* This is a MEX-file for MATLAB.
* Copyright (c) 1984-2000 The MathWorks, Inc.
*=======================================================*/
#include "mex.h"
/* Computational subroutine */
void convec( double *xr, double *xi, int nx,
double *yr, double *yi, int ny,
double *zr, double *zi)
{
int i,j;
zr[0] = 0.0;
zi[0] = 0.0;
/* Perform the convolution of the complex vectors. */
for(i = 0; i < nx; i++) {
for(j = 0; j < ny; j++) {
*(zr+i+j) = *(zr+i+j) + *(xr+i) * *(yr+j) - *(xi+i)
* *(yi+j);
*(zi+i+j) = *(zi+i+j) + *(xr+i) * *(yi+j) + *(xi+i)
* *(yr+j);
}
}
}
Vista de pagina 80
1 2 ... 76 77 78 79 80 81 82 83 84 85 86 ... 407 408

Comentarios a estos manuales

Sin comentarios