Re: running C++ code with mutiple routines from matlab



runcyclexcski@xxxxxxxxx writes:

I have written an image processing app in Matlab which works fine
when
I analyze images one at a time, but is very slow when I have to
analyze thousands of images in a row. So I re-wrote the image
analysis
routine in C++, compiled in .NET. The C++ code runs about 20 times
faster than Matlab. Being a layman in programming, I am now wondering
how to make matlab talk to C++.

The C++ code is a .cpp file and an .h file. The .cpp file contains ~5
functions that talk to each other, and the main() produces the final
answer. From what I understand to make a .dll I can export functions
one at a time - is that so? If yes, how can I make main () .dll talk
to the .dlls with the seconday functions and then report to matlab?
Or
do I have to bundle all functionalities into the main()?


Or is making a .dll not the right way to go?

You probably want a MEX file. Read about it in the "External
Interfaces" portion of the documentation. In a MEX file, your main()
will be replaced with a mexFunction(), which serves as the interface to
MATLAB. That function will be responsible for retrieving pointers to
the source data, allocating MATLAB output arrays, retrieving pointers to
those output buffers, and calling your computation functions.

The MEX file can have many sub-functions in it. The whole thing still
compiles to a single MEX file. The same would be true for a DLL.
Actually a MEX file *is* a DLL with certain naming conventions, that
MATLAB intrinsically knows how to call.

-Peter
.



Relevant Pages

  • Re: Memory Allocation with a shared library
    ... I dont have alot of matlab expereince I mainly write C and vhdl, ... Well I can compile and run a mex file that returns a output array. ... a mex file if you have a DLL. ... I put all the functionality into libraries and then use MEX as a wrapper layer. ...
    (comp.soft-sys.matlab)
  • Re: running C++ code with mutiple routines from matlab
    ... I analyze images one at a time, but is very slow when I have to ... how to make matlab talk to C++. ... From what I understand to make a .dll I can export functions ... You probably want a MEX file. ...
    (comp.soft-sys.matlab)
  • Re: Memory Allocation with a shared library
    ... I dont have alot of matlab expereince I mainly write C and vhdl, ... Any reason why you are compiling it as a DLL? ... i bealive creating a mex file will cause me to change my ... I have read through the doc, and I keep trying to compile my file using the mex -filname command in matlab but it never works. ...
    (comp.soft-sys.matlab)
  • Re: Memory Allocation with a shared library
    ... I dont have alot of matlab expereince I mainly write C and vhdl, ... Any reason why you are compiling it as a DLL? ... i bealive creating a mex file will cause me to change my ... I have read through the doc, and I keep trying to compile my file using the mex -filname command in matlab but it never works. ...
    (comp.soft-sys.matlab)
  • Re: running C++ code with mutiple routines from matlab
    ... I analyze images one at a time, but is very slow when I have to ... how to make matlab talk to C++. ... A Dll can export more than one function. ...
    (microsoft.public.vc.language)

Loading