【发布时间】:2012-03-28 03:18:49
【问题描述】:
我正在尝试向 Matlab 引擎发送简单的字符串命令。
这是我的代码(除了#include "engine.h" 行之外,我的代码中的其他任何地方都没有与 Matlab API 相关的代码):
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 Ultimate x64 SP1,最新
IDE:Visual Studio 2010,(版本 10.0.40219.1 SP1Rel)
Matlab:7.8.0(R2009a)
【问题讨论】:
标签: c++ visual-studio matlab matlab-engine