Proficient VC and MATLAB joint programming < Nine >--Synthesis example one

Source: Internet
Author: User
Tags header

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")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.