3

Has any one had before this error message :

Undefined function or method 'name of function' for inputs arguments of type 'double'.

I always have this error message when compiling a mex file. I have checked well the path, and it seems to be the right one.

This is my code, the mex file is amortiss.c

#include "mex.h"

/* The computational functions */
void arrayquotient(double input1, double input2, double output1)
{

   output1=input1/input2;

}


/* The gateway function */
void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[])
{
/* variable declarations here */
    double input1;      /* input scalar 1 */
    double input2;       /* input scalar 2*/
    double output1;      /* output scalar 1 */   

/* code here */
    /* get the value of the scalar input1  */
   input1 = mxGetScalar(prhs[0]);

/* get the value of the scalar input2 */
   input2 = mxGetScalar(prhs[1]);

/* get the value of the scalar input3 */
   input3 = mxGetScalar(prhs[2]);

/* create the output scalar1 */
    plhs[0] = mxCreateDoubleScalar(input1/input2);

/* get the value of the scalar output1 */
   output1 = mxGetScalar(plhs[0]);

/* call the computational routines */
arrayquotient(input1,input2,output1);
}

I added the path (command add path) to make sure the mex file amortiss.c exists. Then I created a .m file called arrayquotient.m in which I just wrote the declaration of my function :

function c = arrayquotient(a,b)

But, when compiling, another error message appears:

Error in ==> arrayquotient at 1
function c=arrayquotient(a,b)

??? Output argument "c" (and maybe others) not assigned during call to
"C:\Users\hp\Documents\MATLAB\codes_Rihab\arrayquotient.m>arrayquotient".
4

1 回答 1

1

The function amortiss.c is a c-file and CANNOT be executed as-is by Matlab.
The file, arrayquotient.m, you created is an empty function that does not assign value to its output c.

What you need to do is to mex the c-file amortiss.c to create a mex file amortiss.mexw32 (the extension differs according to your architecture. Use mexext to find out the extension you should be looking for).

In matlab, setup your mex compiler:

>> mex -setup

You will be instructed to choose from compilers installe don your machine and recognized by Matlab.

Once you setup your mex compiler you can go on and mex the c-file

>> mex -O -largeArrayDims amortiss.c

Then you'll have a mex-file amortiss.mexXXX (with 'XXX' depending on your architecture).
You can cll the function like any other function

>> c = amortiss( a, b );
于 2013-05-25T19:15:06.067 回答