Mex-files

fatenov Messages postés 16 Date d'inscription lundi 8 octobre 2007 Statut Membre Dernière intervention 23 novembre 2007 - 18 nov. 2007 à 14:28
baghrir Messages postés 1 Date d'inscription dimanche 18 décembre 2005 Statut Membre Dernière intervention 17 décembre 2009 - 17 déc. 2009 à 13:50
Bonjour à tous,

J'essai d'apprendre à utiliser les mex-files.
J'ai utilisé l'exemple sur le net suivant:


#include "mex.h"
#include <math.h>


void timestwo(double y[], double x[])
{
  y[0] = 2.0*x[0];
  return;
}


void mexFunction( int nlhs, mxArray *plhs[],    
                  int nrhs, const mxArray *prhs[] )
{ double *y;
  double *x;
  unsigned int m, n;


  /* Check for proper number of arguments. */
  if (nrhs !=1) {
    mexErrMsgTxt("Only one input argument allowed."); }
  else if (nlhs !=1) {
    mexErrMsgTxt("Only one output argument allowed."); }


  /* The input x must be a scalar, get the size of x. */
  m = mxGetM(prhs[0]);  /* rows    */
  n = mxGetN(prhs[0]);  /* columns */
  if (!mxIsNumeric(prhs[0]) || mxIsComplex(prhs[0])
      || mxIsSparse(prhs[0]) || !mxIsDouble(prhs[0])
      || !(m ==1 && n ==1))
  {
    mexErrMsgTxt("Input x must be a scalar.");
  }


  /* Create a matrix for the return argument. */
  plhs[0] = mxCreateDoubleMatrix(m, n, mxREAL);
  /* Assign pointers to each input and output. */
  y = mxGetPr(plhs[0]);
  x = mxGetPr(prhs[0]);
  /* Call the timestwo subroutine. */
  timestwo(y, x);
}

Je l'ai enregistré sous "timestwo.c".

Sous matlab, j'ai fait:
<<mex -v -g timestwo.c
ça me crée la .dll
et quand je l'exécute << timestwo(0,1) par exemple il m'affiche cette erreur ??? Only one input argument allowed.

Quelqu'un aura-t-il une idée pour m'aider ???

1 réponse

baghrir Messages postés 1 Date d'inscription dimanche 18 décembre 2005 Statut Membre Dernière intervention 17 décembre 2009
17 déc. 2009 à 13:50
Bonjour,
La fonction "timestwo" n'accèpte qu'une seule entrée:
Si tu écris x = timestwo(4), le résultat sera dans x (x=8).
Et voila
0
Rejoignez-nous