VC怎样才能调用MATLAB的函数

chenyangji 2003-10-20 05:49:36
请高手指教:工程中已经加了libeng.lib和libmx.lib,并且也加了#include"engine.h"
怎么还是不能使用如下函数:mxSetName(T,"T"),engPutArray(engine * ep,mxArray * t),我使用的是VC++6.0和MATLAB6.5.
...全文
143 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
gambolgs 2003-10-31
  • 打赏
  • 举报
回复
这个问题我遇到过的
关键问题在于matlab的版本上,要看这样一句错误提示:
F:\chen101903\chen101903Dlg.cpp(205) : error C2065: 'mxSetName_is_obsolete' : undeclared identifier

如果你到matrix.h中看mxSetName的声明会发现有这样一句

#ifdef V5_COMPAT //具体的宏名字我记不住了,反正是判断是不是和V5兼容
...
#else

#define mxSetName mxSetName_is_obsolete//走这个预处理分枝就等于没有声明mxSetName()了

#endif

于是matrix.h里就相当于根本没有定义mxSetName这个东西.你只需要在
#include "matrix.h"
之前加一句
#define V5_COMPT //具体宏的名字在matrix.h里前面那个地方找

很奇怪的是我用的是完整matlab 6.5版的,居然里面的matrix.h会要求跟第五版兼容...
chenyangji 2003-10-30
  • 打赏
  • 举报
回复
请大家帮帮我:
运行下面语句后
Engine *ep;
mxArray *result=NULL;
double *data;
ep=engOpen("\0")
engEvalString(ep,"a=imread('nameofpictrue');");
result=engGetArray(ep,"a");
data=mxGetPr(result);
int row,col;
row=engGetM(result);
col=engGetN(result);
for(int i=1;i<row*col;i++);
printf("%lf",data[i]);
怎么打印结果都是0。请高手指教!





chenyangji 2003-10-30
  • 打赏
  • 举报
回复
cxf1976(九都伯爵):
你好!
我的分虽不多,但大家可以交个朋友嘛!
请告知具体方案,你要多少分,只要我有都给!
chenyangji 2003-10-29
  • 打赏
  • 举报
回复
请高手指教:执行过engEvalString(ep,"a=imread('picturename.bmp');");后如何获得图像每个象素的值,即矩阵a的每个元素。
jiangdazhi 2003-10-26
  • 打赏
  • 举报
回复
我现在也在朝这方面学习
顶一下
cxf1976 2003-10-25
  • 打赏
  • 举报
回复
有些库文件lib肯能没有做好,另外你的分太少了,给我两百全套方案给你,呵呵
seayou 2003-10-25
  • 打赏
  • 举报
回复
matlab是什么啊
SlayerCarrier 2003-10-24
  • 打赏
  • 举报
回复
我也是,学习MATLAB和VC++.qq64984581.
你的错误是编译错误,不是link错误,所以先检查一下有没语法问题,.
chenyangji 2003-10-24
  • 打赏
  • 举报
回复
大家好!

如对MATLAB和VC++有兴趣,有可能的话请与我聊系,我的QQ是116463281,Email是chenyangji2003@yahoo.com.cn。
对上面的问题,如有什么建议和看法请告知。谢谢!
doctorx4587 2003-10-22
  • 打赏
  • 举报
回复
我也正在学习MATLAB和VC++,所以近来看看,学习学习,,,,,
chenyangji 2003-10-21
  • 打赏
  • 举报
回复
程序如下:
void CChen101903Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
Engine *ep;
mxArray *T=NULL,*result=NULL,*mFs=NULL,*mnfft=NULL;
double datax[1024];
char buffer[1024];
for(int j=0;j<1024;j++)
{
double samt=(double)(1.0/1024);
datax[j]=sin(2.0*63.0*samt*3.1415926+1.15*3.1415926);
}
double *pPxx,*pFxx;
if(!(ep=engOpen("\0")))
{
fprintf(stderr,"\n Can't start MATLAB engine\n");
exit(-1);
}
double Fs[1]={1024};
double nfft[1]={1024};
T=mxCreateDoubleMatrix(1,1024,mxREAL);
mnfft=mxCreateDoubleMatrix(1,1,mxREAL);
mFs=mxCreateDoubleMatrix(1,1,mxREAL);
mxSetName(T,"T");
mxSetName(mnfft,"mnfft");
mxSetName(mFs,"mFs");
memcpy((char*)mxGetPr(T),(char*)datax,1024*sizeof(double));
memcpy((char*)mxGetPr(mnfft),(char*)nfft,sizeof(double));
memcpy((char*)mxGetPr(mFs),(char*)Fs,sizeof(double));
engPutArray(ep,T);
engPutArray(ep,mnfft);
engPutArray(ep,mFs);
engEvalString(ep,"[pxx,fo]=psd(T,mnfft,mFs);");
engOutputBuffer(ep,buffer,512);
result=engGetArray(ep,"pxx");
pPxx=mxGetPr(result);
result=engGetArray(ep,"fo");
pFxx=mxGetPr(result);
engEvalString(ep,"figure();plot(fo,10*log10(pxx));");
engEvalString(ep,"title('功率谱分析');");
engEvalString(ep,"xlabel('Hz');");
engEvalString(ep,"ylabel('db');");

mxDestroyArray(T);
mxDestroyArray(mFs);
mxDestroyArray(result);
engEvalString(ep,"close;");
engClose(ep);
}
提示如下:

错误--------------------Configuration: chen101903 - Win32 Debug--------------------
Compiling...
chen101903Dlg.cpp
F:\chen101903\chen101903Dlg.cpp(205) : warning C4002: too many actual parameters for macro 'mxSetName'
F:\chen101903\chen101903Dlg.cpp(205) : error C2065: 'mxSetName_is_obsolete' : undeclared identifier
F:\chen101903\chen101903Dlg.cpp(206) : warning C4002: too many actual parameters for macro 'mxSetName'
F:\chen101903\chen101903Dlg.cpp(207) : warning C4002: too many actual parameters for macro 'mxSetName'
F:\chen101903\chen101903Dlg.cpp(211) : warning C4002: too many actual parameters for macro 'engPutArray'
F:\chen101903\chen101903Dlg.cpp(211) : error C2065: 'engPutArray_is_obsolete' : undeclared identifier
F:\chen101903\chen101903Dlg.cpp(212) : warning C4002: too many actual parameters for macro 'engPutArray'
F:\chen101903\chen101903Dlg.cpp(213) : warning C4002: too many actual parameters for macro 'engPutArray'
F:\\chen101903\chen101903Dlg.cpp(216) : warning C4002: too many actual parameters for macro 'engGetArray'
F:\chen101903\chen101903Dlg.cpp(216) : error C2065: 'engGetArray_is_obsolete' : undeclared identifier
F:\chen101903\chen101903Dlg.cpp(216) : error C2440: '=' : cannot convert from 'int' to 'struct mxArray_tag *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
F:\chen101903\chen101903Dlg.cpp(218) : warning C4002: too many actual parameters for macro 'engGetArray'
F:\chen101903\chen101903Dlg.cpp(218) : error C2440: '=' : cannot convert from 'int' to 'struct mxArray_tag *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
Creating browse info file...

chen101903.exe - 5 error(s), 8 warning(s)

wqs6 2003-10-20
  • 打赏
  • 举报
回复
设置路径:
根据MATLAB所在盘而定,例如我的matlab是装在D盘的,所以需要包含的路径为
D:\MATLAB6p1\extern\include\,在工程中设置
需包含的头文件:
//matlab中的头文件调用matlab的函数
#include "engine.h"
需要连接的LIB库:
D:\MATLAB6p1\extern\lib\win32\digital\df50\libeng.lib D:\MATLAB6p1\extern\lib\win32\digital\df50\libmx.lib 支持mx函数
程序实现:
数据
数组(vc中),用memcpy拷贝到mxArray数组中,用engPutArray移植到matlab中,
用engEvalString执行matlab命令,再用mxGetPr从mxArray中得到数据

Skt32(荒城之月)给的文章很能说明这个问题。
wqs6 2003-10-20
  • 打赏
  • 举报
回复
提示错误是什么?

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧