我想发送简单的字符串命令到Matlab引擎。如何在我的代码中使用Matlab引擎(用于调用`engOpenSingleUse()`)?
这是我的代码(没有Matlab的API相关的代码,其他地方在我的代码,除了#include "engine.h"
线):
void MatlabPlotter::DrawInMatlab() const
{
std::string PlotCommand = "x=[0 1 2 3 4 5];y=[0 1 4 9 16 25];plot(x, y);";
void * vpDcom = NULL;
int iReturnValue;
engOpenSingleUse(PlotCommand.c_str(), vpDcom, &iReturnValue);
}
代码编译和运行成功,没有任何编译器错误或运行时错误消息。 “Matlab命令窗口”打开;我得到像下面的屏幕:
正如你看到的,命令窗口是空的。屏幕上没有绘图窗口。
当我手动键入命令到这个窗口,我得到的绘制,没有任何错误,象下面这样:
这是engOpenSingleUse()
功能的官方文档页面:
http://www.mathworks.com/help/techdoc/apiref/engopensingleuse.html
我在我的项目中添加了<MatlabInstallationDir>\extern\lib\win64\microsoft\libeng.lib
库(我正在编译x64调试配置)。
我包含<MatlabInstallationDir>\extern\include\engine.h
头文件。
我在主Matlab窗口输入!matlab /regserver
命令(如engOpenSingleUse()
函数的文档页面所述),以确保Matlab引擎已注册到我的操作系统。
为什么当我拨打engOpenSingleUse()
函数时什么都不会发生?
当我在PlotCommand
对象中发送字符串命令以绘制绘图图时,为什么不弹出绘图窗口?
我在做什么错?
操作系统:Windows 7旗舰版64位SP1,跟上时代的
IDE:Visual Studio 2010中,(版10.0.40219.1 SP1Rel)
Matlab的:7.8.0(R2009a)