MATLAB REAL-TIME WORKSHOP 7 - TARGET LANGUAGE COMPILER Manuel d'utilisateur Page 81

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 408
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 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);
}
}
}
Vue de la page 80
1 2 ... 76 77 78 79 80 81 82 83 84 85 86 ... 407 408

Commentaires sur ces manuels

Pas de commentaire