How to build .m files into .mex files correctly
Mostra commenti meno recenti
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']);
end
end
Risposta accettata
Più risposte (2)
Ran
il 6 Giu 2012
Ran
il 6 Giu 2012
0 voti
1 Commento
Kaustubha Govind
il 7 Giu 2012
Ran: Could you please accept my answer if it helps. Thanks!
Categorie
Scopri di più su Write C Functions Callable from MATLAB (MEX Files) in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!