1

I'm having a problem when I try to call a Matlab funcion from my C++ code.

When I call engOpen, it always returns NULL. Here is the code:

Engine *m_pEngine;
m_pEngine = engOpen(NULL);
if(m_pEngine == NULL)
{
   cout << "Error" << endl;
   exit(1);
}

Does somebody know how to solve this?

Thanks !!!

Sara
  • 833
  • 2
  • 9
  • 21

2 Answers2

2

If you look at the engOpen documentation it says:

On Windows systems, engOpen opens a COM channel to MATLAB. The MATLAB software you registered during installation starts. If you did not register during installation, on the command line you can enter the command:

matlab /regserver

I'm not sure that is your problem, but it seems worth a try.

Praetorian
  • 106,671
  • 19
  • 240
  • 328
  • Yeah, sorry, I forgot to say I tried that already. When I execute matlab /regserver on the command line, a window pops up that says "Unable to set Registry value for MATLAB.AutoServer.Single. You may not have sufficient privileges. Re-run MATLAB as a user with Administrator access". But I am the Administrator of this machine, so I'm not sure what the problem is. – Sara Jul 20 '11 at 16:44
  • Sorry sorry, I feel stupid. I forgot to run the command line as an Administrator. – Sara Jul 20 '11 at 16:46
0

you need to launch Matlab in administrator mode right-click on the Matlab icon and select "run as administrator"

You should check this even if you have registered Matlab during admin, if it is not currently registered as the COM link then it will not support engOpen.

also engOpen("") should work

This is not quite all that there is to it, there are certain mods that you have to keep in mind for the IDE configuration (or the linker and include options if you're using a command-line compiler).

Here's a Matlab admin page to resolve these problems. Beyond the COM link issue.

https://www.mathworks.com/matlabcentral/answers/100603-how-can-i-compile-a-matlab-engine-application-using-microsoft-visual-studio-9-0-or-10-0