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

📄 vceng1view.cpp

📁 《MATLAB实用指南》系列丛书源代码。
💻 CPP
字号:
// VCeng1View.cpp : implementation of the CVCeng1View class
//

#include "stdafx.h"
#include "VCeng1.h"

#include "VCeng1Doc.h"
#include "VCeng1View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CVCeng1View

IMPLEMENT_DYNCREATE(CVCeng1View, CView)

BEGIN_MESSAGE_MAP(CVCeng1View, CView)
	//{{AFX_MSG_MAP(CVCeng1View)
	ON_COMMAND(ID_Menu_VCeng1, OnMenuVCeng1)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CVCeng1View construction/destruction

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

}

CVCeng1View::~CVCeng1View()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CVCeng1View drawing

void CVCeng1View::OnDraw(CDC* pDC)
{
	CVCeng1Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CVCeng1View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CVCeng1View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CVCeng1View message handlers

void CVCeng1View::OnMenuVCeng1() 
{
 Engine *ep; ///////////引擎对象指针声明
 double t[1]; 
 t[0]=6.28; 
 mxArray *T=NULL; 
 if(!(ep=engOpen(NULL)))//////////打开引擎
 { AfxMessageBox("Can not open the matlab engine!"); exit(-1);} 

 T=mxCreateDoubleMatrix(1,1,mxREAL); 
 memcpy((char*)mxGetPr(T),(char*)t,1*sizeof(double)); 
 ///////////////////////通过引擎库函数调用matlab命令
 engPutVariable(ep,"ep_T",T); 
 engEvalString(ep,"ep_T1=0:pi/48:ep_T;"); 
 engEvalString(ep,"ep_D=sin(ep_T1)"); 
 engEvalString(ep,"plot(ep_T1,ep_D,'r-');"); 

 engEvalString(ep,"xlabel('t');"); 
 engEvalString(ep,"ylabel('sin(t)');"); 
 engEvalString(ep,"title('sin(x) curve');"); 
 AfxMessageBox("关闭引擎");
 engClose(ep); //////////关闭引擎
 mxDestroyArray(T); ///////内存释放
}
/////////////////结束

⌨️ 快捷键说明

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