简体   繁体   中英

passing parameter for calling a matlab function in c++

using deployment tool I produced the c++ shared library. My Matlab Function just get one input parameter which is the path of images, and return a 1*6 vector in double;

I searched a lot on net and found the steps the calling Matlab functions in C++; Now I know that at first I must initialize the application and the library such as these:

#include <libname.h>
mclInitializeApplication();
mclInitializeApplication();

and I know that at last I must call functions for terminate:

<libname>Terminate();
mclTerminateApplication();

but I dont know how can I pass a string to the matlab function. I write so:

string path = "C:\\Users\\user\\Documents\\MATLAB\\Mypic.jpg";
mwArray im_path;

In calling im_path.SetData() I do not know which type I must use. the types of first parameter, does not include any type related to string. Also I do not know how to call the Matlab function and which parameters I must pass to that.

please help me if you do that call before.

thank you so much!

To pass a string as the input parameter to Matlab, you can simply use:

mwArray im_path(path.c_str());

And you also need to initialize the function first and terminate it afterwards. Suppose your function are like function res = func(path) and being deployed to func.lib , you need:

funcInitialize()
...
mwArray res(1, 1,  mxDOUBLE_CLASS); // suppose the result is a double
func(1, res, im_path);              // call it here
...
funcTerminate();

Check out this post for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM