⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 engtestview.cpp

📁 是“MATLAB混合编程与工程应用”一书的源码
💻 CPP
字号:
// EngTestView.cpp : implementation of the CEngTestView class
//

#include "stdafx.h"
#include "EngTest.h"
#include "Engine.h"
#include "EngTestDoc.h"
#include "EngTestView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CEngTestView

IMPLEMENT_DYNCREATE(CEngTestView, CView)

BEGIN_MESSAGE_MAP(CEngTestView, CView)
	//{{AFX_MSG_MAP(CEngTestView)
	ON_COMMAND(ID_ENGMATRIX, OnEngmatrix)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEngTestView construction/destruction

CEngTestView::CEngTestView()
{
	// TODO: add construction code here

}

CEngTestView::~CEngTestView()
{
}

BOOL CEngTestView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CEngTestView drawing

void CEngTestView::OnDraw(CDC* pDC)
{
	CEngTestDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CEngTestView printing

BOOL CEngTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CEngTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CEngTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CEngTestView diagnostics

#ifdef _DEBUG
void CEngTestView::AssertValid() const
{
	CView::AssertValid();
}

void CEngTestView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CEngTestDoc* CEngTestView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEngTestDoc)));
	return (CEngTestDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CEngTestView message handlers

void CEngTestView::OnEngmatrix() 
{ int i,j;
  CClientDC pDC(this);
  
  Engine *ep;
  mxArray *T,*F;

  double data[3][3]={{11.2,20.5,12.3},{10.8,10.79,10.88},{12.16,9.8,11.5}};
  double fdata[3][3];
  CString temp;
pDC.TextOut(200,10,"原矩阵为:");
for( i=0;i<3;i++)
	 for( j=0;j<3;j++)
	 {	
		 temp.Format("%4.2f",data[i][j]);
		 pDC.TextOut(100+j*100,100+i*100,temp);
     }
  ep=engOpen(NULL);
if(ep==NULL)
  {
	 MessageBox(NULL,"can't open matlab engine",MB_OK);
       engClose(ep);
	   return ;
  }
  T=mxCreateDoubleMatrix(3,3,mxREAL);
  F=mxCreateDoubleMatrix(3,3,mxREAL);
  if(T==NULL||F==NULL)
  {
	 MessageBox(NULL,"can't create mxArray",MB_OK);
       engClose(ep);
	   return ;
  
  }
memcpy((void*)mxGetPr(T),(void*)data,sizeof(data));
 int status=engPutVariable(ep,"T1",T);
 if(status!=0)
 {  
	  MessageBox(NULL,"Error using matPutVariable",MB_OK);
       mxDestroyArray(T);
       mxDestroyArray(F);
	  engClose(ep);
	   return ;
 }
 status= engEvalString(ep,"C=watermark_lsb_embed(T1)");
if(status!=0)
 {
	MessageBox(NULL,"Error excute matlab  command! ",MB_OK);
    mxDestroyArray(T);
    mxDestroyArray(F);
 	// TODO: Add your command handler code here
	
}
 F=engGetVariable(ep,"C");
memcpy((void*)fdata,(void*)mxGetPr(F),sizeof(fdata));
 mxDestroyArray(T);
 mxDestroyArray(F);
 engClose(ep);
pDC.TextOut(500,10,"逆矩阵为:");
 for( i=0;i<3;i++)
	 for( j=0;j<3;j++)
	 {	
		 temp.Format("%4.2f",fdata[i][j]);
		 pDC.TextOut(500+j*100,100+i*100,temp);
	  
	 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -