Hi All,
I am trying to build all my M files into MEX files so that I can give them to other users to use without disclosing the source code. I used the following steps to create (suppose I have a function blank saved in blank.m, code pasted down at the bottom):
Platform: Windows 7, with Matlab 2010b, visual studio 2010
1. convert M into C++ header and Library by:
mcc -W cpplib:blank -T link:lib blank.m
2. Use the generated blank.h and blank.lib, I create a blankm.cpp which looks like
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, mxArray* prhs[]){ // validate input argument number if (nrhs < 1) { mexErrMsgTxt("At least the file name is required."); } else if (nrhs > 1) { mexErrMsgTxt("Too many input arguments."); } // validate output argument number if (nlhs > 1) { mexErrMsgTxt("Too many output arguments."); } mlxBlank(nlhs, plhs, nrhs, prhs);}
3. Then, I compiled it using matlab:
mex blankm.cpp -L blank.lib
Or compile it in Visual Studio 2010. All of the above steps went well with no problem. So far I have generated blankm.mexw64 successfully. If I input the following script in Matlab, it comes out with nothing
blandm(' a ')
However, if I input like
a = blankm(' a ');
I'll get an error
??? One or more output arguments not assigned during call to "blankm".
Any idea on this? I did something wrong. Or, the whole path is not correct? Thank you in advance. function str2 = blank(str)
if ischar(str) str2 = fliplr(deblank(fliplr(deblank(str)))); else error(['input is not a string']); endend
Best Answer