Tools: VC6.0 + MATLAB 6.5
Realization function: User input data, complete data fitting
Preparation: Set up library and header file paths in VC, see Joint programming <6> <7>
Steps:
1, the establishment of a CESHIDLL.M-m function file, the function is to enter two sets of data to complete the interpolation of two sets of figures, and the results graphically indicated:
The contents of the CESHIDLL.M file are as follows:
function ceshidll(x,y)
a=min(x):0.1:max(x);
b = interp1(x,y,a,''spline'');%一维插值函数
plot(x,y,''*'',a,b);
2, in the MATLAB command with the following commands to compile the function ceshidll.m:
>> mcc -t -W libhg:dlltest -T link:lib -h libmmfile.mlib ceshidll.m
参数说明:
-t 将m文件编译为C\C++代码
-W libhg:dlltest 生成使用C函数图形库的文件,生成的文件名为dlltest
-T link:lib 生成库文件
-h 辅助选项,可以将任何被调用的辅助函数都包含到编译的文件中
libmmfile.mlib连接任何需要的共享函数库
ceshidll.m 被编译的文件名
After compiling, the following files will be generated in the current directory of MATLAB: CESHIDLL.C, Ceshidll.h, dlltest.c, Dlltest.exports, Dlltest.h, Dlltest.mlib, Dlltest.exp, Dlltest.lib, Dlltest.dll. where Dlltest.h, Dlltest.lib and Dlltest.dll files are what we need.
3, to establish a fit based on the dialog box MFC (EXE) project. Add a button called fit on the panel, as shown in the picture.
Figure 1
4, the file dlltest.h, dlltest.lib and Dlltest.dll copy to the current directory of the project. And the file dlltest.h, dlltest.lib into the project: in the VC integrated environment using the menu Project->add to Projec->files, select just copied to the directory of files.
5, add the header file in the program, and introduce the library file:
Add the following code at the beginning of the FitDlg.cpp file:
#include "matlab.h"
#include "dlltest.h"
#pragma comment(lib,"dlltest")