我正在尝试向 Matlab 引擎发送简单的字符串命令。
这是我的代码(我的代码中的其他任何地方都没有与 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 /regserver
在 Matlab 主窗口中输入了命令(如engOpenSingleUse()
函数文档页面中所述),以确保 Matlab 引擎已注册到我的操作系统。
engOpenSingleUse()
为什么我调用该函数时没有任何反应?
为什么我在对象中发送字符串命令进行绘图时没有弹出绘图窗口PlotCommand
?
我究竟做错了什么?
操作系统:Windows 7 Ultimate x64 SP1,最新
IDE:Visual Studio 2010,(版本 10.0.40219.1 SP1Rel)
Matlab:7.8.0 (R2009a)