MEX ERRORs: Calling C++ code from MATLAB
3 views (last 30 days)
I am trying to run this code (GZipped Tar Ball) in MATLAB. The main.m function calls a number of C files.
I am not overly familiar with C code. I have tried to mex it, so I can run the MATLAB script, but something is going wrong.
- I am running MATLAB 2009a on Vista. 32 bit.
- I type mex –setup and see that I have the default MATLAB complier installed (Though I do have visual studio installed with the latest SDK)
- Then I just type mex –fileName.c into the MATLAB command line (having cd’d to that dir). The command then fails with a whole host of error messages. EG Undeclared identifier ..., LCC pre-processor error: could not find file values.h
- I note that the readme file contains a note saying “This C program needs some declarations in TvarTypes.h”: I don’t know what this means. Maybe it is the reason I am getting these errors?
Petter on 20 Jan 2011
This piece of software is not written in standard C. The file "values.h" is not part of the standard. Basically whoever wrote the code did not care about portability.
Tim Love on 21 Jan 2011
With 2010a on linux I did
I got a warning about memcpy, but it was otherwise ok. I then run main from within matlab. It chugged along merrily producing graphics and lines like
time = 1080 CpxOrder = 0 RealOrder = 1, particles 100
before seg-faulting. It's rather old C code, and memcpy usage might need tightening up, but it's not completely broken.
HANS on 19 Mar 2018
Hi to all :)
I have name.mex function and many .cpp and .h files related to it. name.mex takes only 1xinf vector which is a complex double values inside and output is the same size vector.
I want to call this name.mex within C++. As I know I have to use "int mexCallMATLAB(int nlhs, mxArray *plhs, int nrhs, mxArray *prhs, const char *command_name);"
Please could anybody give a usage example in C++ ? I guess I have to use "ifstream" to load the data vector before I use the function but do I have to define via "mxArray" or ??