我正在尝试向 Matlab 引擎发送简单的字符串命令。
这是我的代码(我的代码中其他任何地方都没有与 Matlab API 相关的代码,除了#include "engine.h"
line):
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 命令行窗口”打开;我得到如下屏幕:
![Empty Matlab Command Window](https://i.stack.imgur.com/U5vw8.png)
如您所见,命令窗口是空的。屏幕上没有绘图窗口。
当我手动在该窗口中键入命令时,我得到的绘图没有任何错误,如下所示:
![Manually typed command to the command window](https://i.stack.imgur.com/FNDRH.png)
这是官方文档页面engOpenSingleUse()
功能:
http://www.mathworks.com/help/techdoc/apiref/engopensingleuse.html
I added <MatlabInstallationDir>\extern\lib\win64\microsoft\libeng.lib
我的项目中的库(我正在 x64 调试配置中进行编译)。
包括我<MatlabInstallationDir>\extern\include\engine.h
头文件。
我输入了!matlab /regserver
命令到Matlab主窗口(如Matlab文档页面中所述)engOpenSingleUse()
函数)以确保 Matlab 引擎已注册到我的操作系统。
为什么我打电话时没有任何反应engOpenSingleUse()
功能?
为什么我在发送字符串命令时没有弹出绘图窗口PlotCommand
对象绘制绘图?
我究竟做错了什么?
操作系统:Windows 7 Ultimate x64 SP1,最新
IDE:Visual Studio 2010,(版本 10.0.40219.1 SP1Rel)
Matlab:7.8.0(R2009a)