0

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!

herohuyongtao
  • 49,413
  • 29
  • 133
  • 174
  • @herohuyongtao, what's with the [meta tag](http://blog.stackoverflow.com/2010/08/the-death-of-meta-tags/)? – Charles Apr 14 '14 at 23:51
  • @Charles Here, `mixed-programming` is short for [Mixed-Language Programming](http://goo.gl/V8vyia), in which the source code is written in two or more languages, i.e. enables you to call existing code that may be written in another language. I don't quite agree it is a meta tag. I have answered several questions, seen [here](http://goo.gl/Ye7FhN). They actually did want to do this but they just list the different languages involved. But what they really want to do is mixing them together, not to do it in all these languages. Such a tag can help to describe such questions more accurately. – herohuyongtao Apr 15 '14 at 04:01
  • @herohuyongtao, in that case please update the tag wiki and excerpt to indicate that it's specific jargon and *not* a meta tag to be used when writing code in more than one language. That might help a bit. It's still a horrible tag name... – Charles Apr 15 '14 at 06:45
  • @Charles Updated the excerpt. Will it help if I replace its name by full name like `mixed-language-programming`? – herohuyongtao Apr 15 '14 at 07:35
  • @herohuyongtao, unfortunately tags have a 25 character limit, and the full wording is 26 characters. It wouldn't help *too* much, as the root cause of the suckitude is MS picking a very generic term... – Charles Apr 15 '14 at 16:52

1 Answers1

0

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.

herohuyongtao
  • 49,413
  • 29
  • 133
  • 174
  • thank you ;) but I read this post before! what about the output value? How can I get that? and why you did not use setdata or get function? – user3159964 Feb 26 '14 at 12:09