注册 | 登录

解决Error Message Mex file Matlab

itPublisher 分享于



推荐:关于C++与matlab7.0的混合编程,MEX.PL: Error: No file names given!

 >>mex-setup     Usage:         MEX [option1 ... optionN] sourcefile1 [... sourcefileN]             [objectfile1 ... objectfileN] [libraryfile1 ... li

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)



/* 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 */

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
matlab mex
  this question
edited May 25 '13 at 16:22 Mahm00d 1,969 5 25 50 asked May 25 '13 at 8:47 Mayar Rihab 23 4      Are you sure you're actually compiling the MEX? Usually you would get "Undefined function etc." if you hadn't actually compiled the function. –  wakjah May 25 '13 at 11:17      I'm a little confused. Is the function you are trying to write called amortiss or arrayquotient? Unless you compile with the correct flags, your compiled mex file will be amortiss. Please report the result of which arrayquotient -all and which amortiss -all. –  nhowe May 25 '13 at 18:06      The assignment to parameter output1 in arrayquotient does not change the different variable output1 in mexFunction. If output1 in mexFunction were assigned, that alone would not change the value in plhs[0]. You should check nrhs to avoid crashing Matlab on bad inputs. –  aschepler May 25 '13 at 19:22      Thank you all for responding.My mex file is"amortiss.c" and the function is called "arrayquotient".I've compiled the Mex file using the Microsoft Visual C++ 2008 Express compiler but once I get in the repetoire I don't find the " .mexw32" file neither of the "arrayquotient" function nor of the "amortiss.c" file. Do you think that this is the problem ? and what can I do now ? please I appreciate your help!! –  Mayar Rihab May 26 '13 at 9:11


1 Answers


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.

推荐:MATLAB mex -setup 使用

Would you like mex to locate installed compilers [y]/n 的时候输入n 3、此时会列出matlab支持的编译器 [1] Intel C++ 9.1 (with Microsoft Visual C++ 2005

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 );

  this answer
answered May 25 '13 at 19:15 Shai 53k 18 92 171      @ Shai,thank you for responding.I've done what you said and I've chosen the Compiler:Microsoft Visual C++ 2008 Express.I've also deleted the M file "arrayquotient.m" Then here is what I typed: mex amortiss.c >> c =2.; >> b = 3.; >> d = arrayquotient(c,b) ??? Invalid MEX-file 'C:\Users\hp\Documents\MATLAB\arrayquotient.mexw32': C:\Users\hp\Documents\MATLAB\arrayquotient.mexw32 n’est pas une application Win32 valide. what should I do now ??? I appreciate your help !! –  Mayar Rihab May 26 '13 at 8:52      what is the output of >> mexext? –  Shai May 26 '13 at 9:55      when I type >> mexext it gives me: mexw32 –  Mayar Rihab May 27 '13 at 9:02      You should remove arrayquotient.mex32 and run >> c = amortiss( a, b ); –  Shai May 27 '13 at 9:09 1   I changed the function's name and it worked well.It is just that simple.Anyway thank you very much for your precious help.At the moment, it is working well. Thanks a lot for all your advice and help. –  Mayar Rihab May 28 '13 at 20:38  |  show more comments

推荐:Matlab Mex应用

MEX-files Guide Introduction Introduction to MEX-files Getting help Compiling MEX-files System setup and configuration Testing your system with exampl








您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱