| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 604 人关注过本帖
标题:vc++调用matlab引擎的API函数出错
只看楼主 加入收藏
sunminmin
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2011-5-5
收藏
 问题点数:0 回复次数:0 
vc++调用matlab引擎的API函数出错
程序代码:
帮忙看看void CTxtToMapDlg::OnButtonTxtToMap()为何不正确? 


个人觉得  engEvalString(ep,"M = dlmread(m_FilePath','',');"); //m_FilePath保存map.txt的路径,读取map.txt文件数据  这里有错??   但不确定。



 //用来获取文件的路径,并保存进m_FilePath(注:m_FilePath为编辑框的标号,编辑框用来显示路径名用)
void CTxtToMapDlg::OnButtonBrowsing()
{
    // TODO: Add your control notification handler code here
    char szFilters[] = "MyType Files (*.txt)|*.txt|All Files (*.*)|*.*||";
   
    CFileDialog fileDlg (TRUE, "txt", "*.txt",OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);
   
    // Display the file dialog. When user clicks OK, fileDlg.DoModal()
    // returns IDOK.
    if( fileDlg.DoModal()==IDOK )
    {
        CString pathName = fileDlg.GetPathName();
       
        m_FilePath = pathName;     //m_FilePath里保存txt文件的路径
       
        UpdateData(FALSE);  
    }
} 




//处理txt中数据绘图
void CTxtToMapDlg::OnButtonTxtToMap()
{
    // TODO: Add your control notification handler code here
   
   
    Engine *ep;              
   
    if (!(ep = engOpen(NULL))) //打开Matlab引擎
       
    {             
       
        AfxMessageBox ("Can't start MATLAB engine", MB_OK);
       
        exit(-1);
    }
    
    int MCOUNT = 4225;               //map.txt中有4225行,即4225个(x,y,z)坐标
    int N = 65;                     //x,y值为1,2,3,4,.......,65
   
    mxArray *M = mxCreateDoubleMatrix(MCOUNT,3,mxREAL);  //MCOUNT*3矩阵用来放txt中的三列数据
  //mxCreateDoubleMatrix(m, n, mxREAL); 创建m*n的矩阵
   
    mxArray *x = mxCreateDoubleMatrix(MCOUNT,1,mxREAL);//定义存放txt第一列即x坐标的矩阵
    mxArray *y = mxCreateDoubleMatrix(MCOUNT,1,mxREAL);
    mxArray *z = mxCreateDoubleMatrix(MCOUNT,1,mxREAL);
   
    mxArray *xx = mxCreateDoubleMatrix(N,N,mxREAL);
    mxArray *yy = mxCreateDoubleMatrix(N,N,mxREAL);
    mxArray *zz = mxCreateDoubleMatrix(N,N,mxREAL);
   
    engPutVariable(ep,"M",M);  //把变量M写进matlab的工作空间
    engPutVariable(ep,"x",x);
    engPutVariable(ep,"y",y);
    engPutVariable(ep,"z",z);

    engPutVariable(ep,"xx",xx);
    engPutVariable(ep,"yy",yy);
    engPutVariable(ep,"zz",zz);
   
    engEvalString(ep,"M = dlmread(m_FilePath','',');"); //m_FilePath保存map.txt的路径,读取map.txt文件数据
   
    engEvalString(ep,"x = M(:,1)");             //取第一列
    engEvalString(ep,"y = M(:,2)");             // 取第二列
    engEvalString(ep,"z = M(:,3)");             // 取第三列
    engEvalString(ep,"xx = reshape(x,65,65)");   //重构为size=65*65的方格
    engEvalString(ep,"yy = reshape(y,65,65)");   //重构为size=65*65的方格
    engEvalString(ep,"zz = reshape(z,65,65)");   //重构为size=65*65的方格
    engEvalString(ep,"surf(xx,yy,zz)");            //绘图
       
}




map.txt中数据格式,每一行为一个(x,y,z)坐标:
  1.0000000e+000  1.0000000e+000  2.0000000e+000
  1.0000000e+000  2.0000000e+000  2.4651125e+000
  1.0000000e+000  3.0000000e+000  2.4267769e+000
   。。。




[ 本帖最后由 sunminmin 于 2011-5-12 13:36 编辑 ]
搜索更多相关主题的帖子: matlab 
2011-05-12 13:17
快速回复:vc++调用matlab引擎的API函数出错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.061282 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved