📄 mfcprjview.cpp
字号:
// mfcprjView.cpp : implementation of the CMfcprjView class
//
#include "stdafx.h"
#include "mfcprj.h"
#include "mfcprjDoc.h"
#include "mfcprjView.h"
#include "matlab.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static double data[] = { 21, 3, 15, 57, 12, 83, 6, 90 };
/////////////////////////////////////////////////////////////////////////////
// CMfcprjView
IMPLEMENT_DYNCREATE(CMfcprjView, CView)
BEGIN_MESSAGE_MAP(CMfcprjView, CView)
//{{AFX_MSG_MAP(CMfcprjView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMfcprjView construction/destruction
CMfcprjView::CMfcprjView()
{
// TODO: add construction code here
}
CMfcprjView::~CMfcprjView()
{
}
BOOL CMfcprjView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMfcprjView drawing
void CMfcprjView::OnDraw(CDC* pDC)
{
CMfcprjDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
mysvd(pDC);
}
/////////////////////////////////////////////////////////////////////////////
// CMfcprjView printing
BOOL CMfcprjView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMfcprjView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMfcprjView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
int CMfcprjView::mysvd(CDC *pDC)
{
/* Initialize pointers to array arguments */
mxArray *X = NULL;
mxArray *U = NULL, *S = NULL, *V = NULL;
char str[20*sizeof(double)];
double *ptr;
int nHeight=20;
pDC->TextOut(0,0,"Hello Everyone!");
pDC->TextOut(0,nHeight,"This is a demo of calling SVD function directly");
pDC->TextOut(0,2*nHeight,"from Win32 Console Application,which has the");
pDC->TextOut(0,3*nHeight,"siminar functionality as the MATLAB function");
pDC->TextOut(0,4*nHeight,"SVD - Singular value decomposition.");
mlfEnterNewContext(0, 0);
mlfAssign(&X, mlfDoubleMatrix(4, 2, data, NULL));
/* Compute the singular value decomposition and print it */
mlfAssign(&S, mlfSvd(NULL, NULL, X, NULL));
//mlfPrintf("One input, one output:\n");
pDC->TextOut(0,7*nHeight,"One input, one output:");
//mlfPrintf("S = \n"); mlfPrintMatrix(S);
pDC->TextOut(0,8*nHeight,"S = ");
ptr=mxGetPr(S);
sprintf(str,"%12.4f",ptr[0]);
pDC->TextOut(0,9*nHeight,str);
sprintf(str,"%12.4f",ptr[1]);
pDC->TextOut(0,10*nHeight,str);
/* Multiple output arguments */
mlfAssign(&U, mlfSvd(&S, &V, X, NULL));
// mlfPrintf("One input, three outputs:\n");
pDC->TextOut(0,12*nHeight,"One input, three outputs:");
//mlfPrintf("U = \n"); mlfPrintMatrix(U);
pDC->TextOut(0,13*nHeight,"U = ");
ptr=mxGetPr(U);
sprintf(str,"%12.4f\t%12.4f\t%12.4f\t%12.4f",ptr[0],ptr[4],ptr[8],ptr[12]);
pDC->TextOut(0,14*nHeight,str);
sprintf(str,"%12.4f\t%12.4f\t%12.4f\t%12.4f",ptr[1],ptr[5],ptr[9],ptr[13]);
pDC->TextOut(0,15*nHeight,str);
sprintf(str,"%12.4f\t%12.4f\t%12.4f\t%12.4f",ptr[2],ptr[6],ptr[10],ptr[14]);
pDC->TextOut(0,16*nHeight,str);
sprintf(str,"%12.4f\t%12.4f\t%12.4f\t%12.4f",ptr[3],ptr[7],ptr[11],ptr[15]);
pDC->TextOut(0,17*nHeight,str);
//mlfPrintf("S = \n"); mlfPrintMatrix(S);
pDC->TextOut(0,19*nHeight,"S = ");
ptr=mxGetPr(S);
sprintf(str,"%12.4f\t%12.4f",ptr[0],ptr[4]);
pDC->TextOut(0,20*nHeight,str);
sprintf(str,"%12.4f\t%12.4f",ptr[1],ptr[5]);
pDC->TextOut(0,21*nHeight,str);
sprintf(str,"%12.4f\t%12.4f",ptr[2],ptr[6]);
pDC->TextOut(0,22*nHeight,str);
sprintf(str,"%12.4f\t%12.4f",ptr[3],ptr[7]);
pDC->TextOut(0,23*nHeight,str);
//mlfPrintf("V = \n"); mlfPrintMatrix(V);
pDC->TextOut(0,25*nHeight,"V = ");
ptr=mxGetPr(V);
sprintf(str,"%12.4f\t%12.4f",ptr[0],ptr[2]);
pDC->TextOut(0,26*nHeight,str);
sprintf(str,"%12.4f\t%12.4f",ptr[1],ptr[3]);
pDC->TextOut(0,27*nHeight,str);
/* Multiple input and output arguments */
mlfAssign(&U, mlfSvd(&S, &V, X, mlfScalar(0.0)));
//mlfPrintf("Two inputs, three outputs:\n");
pDC->TextOut(0,29*nHeight,"Two input, three outputs:");
//mlfPrintf("U = \n"); mlfPrintMatrix(U);
pDC->TextOut(0,30*nHeight,"U = ");
ptr=mxGetPr(U);
sprintf(str,"%12.4f\t%12.4f",ptr[0],ptr[4]);
pDC->TextOut(0,31*nHeight,str);
sprintf(str,"%12.4f\t%12.4f",ptr[1],ptr[5]);
pDC->TextOut(0,32*nHeight,str);
sprintf(str,"%12.4f\t%12.4f",ptr[2],ptr[6]);
pDC->TextOut(0,33*nHeight,str);
sprintf(str,"%12.4f\t%12.4f",ptr[3],ptr[7]);
pDC->TextOut(0,34*nHeight,str);
//mlfPrintf("S = \n"); mlfPrintMatrix(S);
pDC->TextOut(0,36*nHeight,"S = ");
ptr=mxGetPr(S);
sprintf(str,"%12.4f\t%12.4f",ptr[0],ptr[2]);
pDC->TextOut(0,37*nHeight,str);
sprintf(str,"%12.4f\t%12.4f",ptr[1],ptr[3]);
pDC->TextOut(0,38*nHeight,str);
//mlfPrintf("V = \n"); mlfPrintMatrix(V);
pDC->TextOut(0,40*nHeight,"V = ");
ptr=mxGetPr(V);
sprintf(str,"%12.4f\t%12.4f",ptr[0],ptr[2]);
pDC->TextOut(0,41*nHeight,str);
sprintf(str,"%12.4f\t%12.4f",ptr[1],ptr[3]);
pDC->TextOut(0,42*nHeight,str);
mxDestroyArray(X);
mxDestroyArray(U);
mxDestroyArray(S);
mxDestroyArray(V);
mlfRestorePreviousContext(0, 0);
return(EXIT_SUCCESS);
}
/////////////////////////////////////////////////////////////////////////////
// CMfcprjView diagnostics
#ifdef _DEBUG
void CMfcprjView::AssertValid() const
{
CView::AssertValid();
}
void CMfcprjView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMfcprjDoc* CMfcprjView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMfcprjDoc)));
return (CMfcprjDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMfcprjView message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -