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

  • 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 69
2 Creating C Language MEX-Files
2-10
In the above example, scalars are viewed as 1-by-1 matrices. Alternatively, you
can use a special API function called
mxGetScalar that returns the values of
scalars instead of pointers to copies of scalar variables. This is the alternative
code (error checking has been omitted for brevity).
#include "mex.h"
/*
* timestwoalt.c - example found in API guide
*
* Use mxGetScalar to return the values of scalars instead of
* pointers to copies of scalar variables.
*
* This is a MEX-file for MATLAB.
* Copyright (c) 1984-2000 The MathWorks, Inc.
*/
/* $Revision: 1.5 $ */
void timestwo_alt(double *y, double x)
{
*y = 2.0*x;
}
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
double *y;
double x;
/* Create a 1-by-1 matrix for the return argument. */
plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
/* Get the scalar value of the input x. */
/* Note: mxGetScalar returns a value, not a pointer. */
x = mxGetScalar(prhs[0]);
/* Assign a pointer to the output. */
y = mxGetPr(plhs[0]);
Vue de la page 69
1 2 ... 65 66 67 68 69 70 71 72 73 74 75 ... 407 408

Commentaires sur ces manuels

Pas de commentaire