I have a C++ code opening a file and rewriting the file and I want to execute the function thro MATLAB
Mostrar comentarios más antiguos
As I mentioned, I am now having a C++ code opening a file and rewriting the content, and I want to use mex.h to call the function in MATLAB.
for example, I have:
void Write_File(){
ofstream file("abc.txt");
double X=0;
file << setw(12) << 0.0 << " " << setw(12)<< X << endl;
return 0;
}
and now I want to do that in MATLAB. How should I define the mexFunction? what are the arguments, say nlhs, nxArray?
1 comentario
James Tursa
el 14 de Feb. de 2013
Why is your void function returning a value?
Respuestas (1)
James Tursa
el 14 de Feb. de 2013
Editada: James Tursa
el 14 de Feb. de 2013
If you have no inputs or outputs, you can simply create this file:
// writefile.cpp
#include "mex.h"
// add any other supporting code here
void Write_File()
{
ofstream file("abc.txt");
double X=0;
file << setw(12) << 0.0 << " " << setw(12)<< X << endl;
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
Write_File();
}
Mex it at the MATLAB command line with:
mex writefile.cpp
If you get an interactive prompt asking about compilers, enter Y (have MATLAB look for them) and then select a C++ compiler from the list. Note that the LCC compiler that ships with MATLAB is strictly a C compiler, not a C++ compiler.
Call it just like any other MATLAB function:
writefile
Categorías
Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!