📄 testarraydlg.cpp
字号:
// TestArrayDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TestArray.h"
#include "TestArrayDlg.h"
#include "matlab.hpp"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
#pragma comment (lib, "libmatlb.lib")
#pragma comment (lib, "libmx.lib")
#pragma comment (lib, "libmatpm.lib") // c++ maths library
#pragma comment (lib, "libmmfile.lib")
/*
mwArray MyFunc(mwArray x,mwArray y){
mwArray mResult=exp(x)*(4*x ^ 2+2*y ^ 2+4*x*y+2*y+1);
return mResult;
}
typedef mwArray (*PMYFUNC)(mwArray,mwArray);
extern "C"{
int MyThunk(mlfFuncp pFunc, int nArgOut, mxArray **
ArgOut,int nArgIn, mxArray **ArgIn) {
mwArray tmp1=mwArray( ArgIn[0], 0 );
mwArray tmp2=mwArray( ArgIn[1], 0 );
mwArray Out=(*((PMYFUNC)pFunc))(tmp1,tmp2);
ArgOut[0]=Out.FreezeData();
return 1;
}
}
static mlfFuncTabEnt MFuncTab[] ={
{ "MyFunc", (mlfFuncp)MyFunc, MyThunk },
{ 0, 0, 0 }
};
class feval_init {
feval_init() { mlfFevalTableSetup( MFuncTab ); }
static feval_init feval_setup;
};
feval_init feval_init::feval_setup;
*/
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestArrayDlg dialog
CTestArrayDlg::CTestArrayDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestArrayDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestArrayDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestArrayDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestArrayDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestArrayDlg, CDialog)
//{{AFX_MSG_MAP(CTestArrayDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestArrayDlg message handlers
BOOL CTestArrayDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestArrayDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTestArrayDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTestArrayDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTestArrayDlg::OnButton1()
{
// TODO: Add your control notification handler code here
double d[] = { -1, -4, 1, 1, 3, 0, 0, 0, 2 };
mwArray A(3, 3, d);
mwArray arrVal,arrVec;
arrVec = eig(&arrVal,A);
double* a = new double[9];
double* b = new double[9];
CString strVal,strVec,str;
double ntemp;
strVal = "特征值为";
strVec = "特征向量为";
CString strsum ="";
for (int i=0; i < 9; i++)
{
a[i] = *(mxGetPr(arrVal.GetData())+i);
ntemp = a[i];
str.Format("%.2f",ntemp);
strVal = strVal +str;
strVal = strVal + ",";
b[i] = *(mxGetPr(arrVec.GetData())+i);
ntemp = b[i];
str.Format("%.2f",ntemp);
strVec = strVec +str;
strVec = strVec + ",";
}
strsum = strsum + strVal;
strsum = strsum + ";\n";
strsum = strsum + strVec;
MessageBox(strsum);
delete []a;
delete []b;
}
void CTestArrayDlg::OnButton2()
{
// TODO: Add your control notification handler code here
double* a = new double[10];
double dy[] = { 1900, 1910, 1920, 1930, 1940, 1950, 1960, 1970, 1980, 1990};
double dp[] = { 75.995, 91.972, 105.711, 123.203, 131.669, 150.697, 179.323, 203.212, 226.505, 249.633};
mwArray T(1, 9, dy);
mwArray N(1, 9, dp);
mwArray C;
double dx[] = { 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979};
mwArray X(1, 10, dx);
C = interp1(T,N,X,"spline");
CString strVal;
CString str;
double ntemp;
for (int i=0; i < 10; i++)
{
a[i] = *(mxGetPr(C.GetData())+i);
ntemp = a[i];
str.Format("%.3f",ntemp);
strVal = strVal +str;
strVal = strVal + ",\n";
}
MessageBox(strVal);
delete []a;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -