最近经常采用Matlab仿真,然后C语言实现,最后需要将计算结果使用Qt的qwt或者matlab中的plot函数绘图。
因此想借用matlab的plot函数接口,使用VS2015来编写信号处理代码,最后通过绘图来验证。
参考博客:
https://blog.csdn.net/shouzang/article/details/80795945
https://blog.csdn.net/libing403/article/details/79135220
非常感谢!
一、VS2015调用Matlab2016a进行绘图
运行环境
Windows 10 64bit
Visual Studio Community 2015/2017
Matlab 2016a
1.1 检查Matlab对C++编译器的支持情况
打开Matlab,在命令行中输入
mex -setup
如下图所示,此时Matlab已经可以识别VC++ 2015。
以管理员身份运行命令提示符,切换到"matlab.exe"的路径,输入下方命令进行注册。
若不注册,在使用engOpen()打开Matlab引擎会提示失败。
二、VS配置及代码示例
测试Demo
#include
#include
#include
#include"engine.h"
const int BUFFER_SIZE = 1024;
char buffer[BUFFER_SIZE];
void test()
{
Engine* ep;
mxArray *x1 = NULL;
mxArray *y1 = NULL;
if ((ep = engOpen("")) == NULL)
{
printf("Engine Fail\n");
}
engOutputBuffer(ep, buffer, BUFFER_SIZE);
printf("Init Success\n");
double x[5] = { 1.0, 2.5,3.7,4.4,5.1 };
double y[5] = { 3.3,4.7,9.6,15.6,21.3 };
x1 = mxCreateDoubleMatrix(1, 5, mxREAL);
y1 = mxCreateDouble