利用matlab引擎与c++混合编程执行时出现问题
voidCMyproDlg::OnOK(){//TODO:AddextravalidationhereCStringname;CStringsuanzi;UpdateDa...
void CMyproDlg::OnOK()
{
// TODO: Add extra validation here
CString name;
CString suanzi;
UpdateData(true);
char name1[20]={0};
char suanzi1[20]={0};
char szTemp[100]={0};
for(int i=0;i<=name.GetLength()-1;i++)
{
name1[i]=name.GetAt(i);
}
name1[i]='\0';
for(int j=0;j<=suanzi.GetLength()-1;j++)
{
suanzi1[j]=suanzi.GetAt(j);
}
suanzi1[j]='\0';
Engine *ep;
if(!(ep=engOpen(NULL)))
{
fprintf(stderr,"\nCan not start Matlab engine\n");
return;
}
mxArray *t=NULL;
mxArray *s=NULL;
t=mxCreateString(name1);
s=mxCreateString(suanzi1);
engPutVariable(ep,"t",t);
engPutVariable(ep,"s",s);
strcpy(szTemp,"l=imread('");
strcat(szTemp,name1);
strcat(szTemp,"');");
engEvalString(ep,szTemp);
engEvalString(ep,"k=rgb2gray(l);");
engEvalString(ep,"imshow(k);");
strcpy(szTemp,"bw=edge(k,'");
strcat(szTemp,suanzi1);
strcat(szTemp,"');");
engEvalString(ep,szTemp);
engEvalString(ep,"figure;");
engEvalString(ep,"imshow(bw);");
mxDestroyArray(t);
mxDestroyArray(s);
engClose(ep);
// CDialog::OnOK();
}
代码没有错,就是不知道为什么执行的时候执行结果是一闪而过。
请问怎样才可以停留执行结果界面。
若能很好解决问题,我会追加分的!!先谢谢啦 展开
{
// TODO: Add extra validation here
CString name;
CString suanzi;
UpdateData(true);
char name1[20]={0};
char suanzi1[20]={0};
char szTemp[100]={0};
for(int i=0;i<=name.GetLength()-1;i++)
{
name1[i]=name.GetAt(i);
}
name1[i]='\0';
for(int j=0;j<=suanzi.GetLength()-1;j++)
{
suanzi1[j]=suanzi.GetAt(j);
}
suanzi1[j]='\0';
Engine *ep;
if(!(ep=engOpen(NULL)))
{
fprintf(stderr,"\nCan not start Matlab engine\n");
return;
}
mxArray *t=NULL;
mxArray *s=NULL;
t=mxCreateString(name1);
s=mxCreateString(suanzi1);
engPutVariable(ep,"t",t);
engPutVariable(ep,"s",s);
strcpy(szTemp,"l=imread('");
strcat(szTemp,name1);
strcat(szTemp,"');");
engEvalString(ep,szTemp);
engEvalString(ep,"k=rgb2gray(l);");
engEvalString(ep,"imshow(k);");
strcpy(szTemp,"bw=edge(k,'");
strcat(szTemp,suanzi1);
strcat(szTemp,"');");
engEvalString(ep,szTemp);
engEvalString(ep,"figure;");
engEvalString(ep,"imshow(bw);");
mxDestroyArray(t);
mxDestroyArray(s);
engClose(ep);
// CDialog::OnOK();
}
代码没有错,就是不知道为什么执行的时候执行结果是一闪而过。
请问怎样才可以停留执行结果界面。
若能很好解决问题,我会追加分的!!先谢谢啦 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询