How to import C++ arrays into Matlab & loop over a C++ program from within Matlab?
Show older comments
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 Comments
James Tursa
on 3 Mar 2015
Edited: James Tursa
on 3 Mar 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.
Accepted Answer
More Answers (0)
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!