How to import C++ arrays into Matlab & loop over a C++ program from within Matlab?
Mostrar comentarios más antiguos
I would like to know the particular steps I must take in order to connect Matlab and C++ for the following problems:
1. How can I import the results from a C++ program, in particular a 5-dim array of doubles and a 5-dim array of strings, into Matlab in order to analyse the results? 2. I would like to call a C++ program from within Matlab, handing over one parameter, letting the C++ program run and getting a resulting constant back. Depending on this resulting constant I want to change the input parameter and loop over the C++ program again. It shall result in kind of a golden section search...
I already had a look at the Matlab documentation and in particular the mex function. I managed to install the necessary compilers for mex and can compile the original C++ code. Additionally I tried out the arrayProduct_01.cpp. However, I got lost in the comprehensive documentation and am quite confused by now... What do I really need of all this and how to adjust it for my problem?
Thanks a lot for any help!!
2 comentarios
James Tursa
el 3 de Mzo. de 2015
Editada: James Tursa
el 3 de Mzo. de 2015
Please post a simple version of your code, at least the I/O parts. For a 5-dim array of doubles, the easiest thing would probably be to create an mxArray with the dimensions in reverse order and then use memcpy to copy the entire variable at once. Then use permute to reverse the dimensions of the mxArray. This is to account for the row vs column memory order of elements difference between C and MATLAB.
Respuesta aceptada
Más respuestas (0)
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!