📄 unit1.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include "engine.h" //matlab->extern->include 中有,在projects->options添加include 头文件搜索路径即可
#define BUFSIZE 256
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
Engine *ep;
bool vis;
mxArray *T = NULL, *result = NULL;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
double time[10] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
T = mxCreateDoubleMatrix(1, 10, mxREAL);
memcpy((unsigned char*)mxGetPr(T),time, 10*sizeof(double));
engPutVariable(ep, "T", T);
engEvalString(ep, "D = .5.*(-9.8).*T.^2;");
engEvalString(ep, "plot(T,D);");
//engEvalString(ep,"set(gcf,'Visible','off')") ;
engEvalString(ep, "title('Position vs. Time for a falling object');");
engEvalString(ep, "xlabel('Time (seconds)');");
engEvalString(ep, "ylabel('Position (meters)');");
engEvalString(ep,"saveas(gcf,'2.bmp')") ;
Form1->Image1->Picture->LoadFromFile("C:\\MATLAB7\\2.bmp");
mxDestroyArray(result);
engClose(ep);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormActivate(TObject *Sender)
{
if (!(ep = engOpen("\0"))) {
ShowMessage("Can't Open The Engine!");
}
engSetVisible(ep, 0);
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -