编号
学士学位论文
MATLAB与C的混合编程
学生姓名: 学 号: 系 部: 专 业: 电子信息科学与技术 年 级: 指导教师: 完成日期: 年 月 日
学 士 学 位 论 文
BACHELOR ’S THESIS 中文摘要
对MATLAB与C语言进行混合编程的常用方法(MAT文件、MEX文件、MATLAB计算引擎、MATLAB编译器、MCC和MATCOM)进行了介绍,分析了其实现方法和各自的利弊。通过MAT文件实现与其它编程环境的数据交换,通过MEX文件实现在MATLAB环境中调用其它语言编写的程序,通过MATLAB引擎实现其它编程环境中使用MATLAB的计算功能,通过MATCOM技术将MATLAB的源代码译成同等功能的C源代码。并用实例对MEX文件实现方式进行了较详细的论述。通过混合编程,利用了C语言高效的特点,在发挥MATLAB强大的计算功能的同时,又弥补其执行速度慢的缺点。
关键词:MATLAB; C; MAT文件; MEX文件; MATLAB计算引擎;MATLAB编译器; MCC和MATCOM; 混合编程
Mixed programming technology for MATLAB with
C
Abstract
On MATLAB and C language common methods of mixing programming (MAT files, documents and MATLAB calculation engine MEX MATLAB, the compiler, MCC and MATCOM) are introduced, analyzes its implementation method and their respective advantages and disadvantages. Through the MAT files realization and other programming environment, through the data exchange MEX files in the MATLAB environment of realizing invoke other language program, through On
I
学 士 学 位 论 文
BACHELOR ’S THESIS MATLAB and C language common methods of mixing programming (MAT files, documents and MATLAB calculation engine MEX MATLAB, the compiler, MCC and MATCOM) are introduced, analyzes its implementation method and their respective advantages and disadvantages. Through the MAT files realization and other programming environment, through the data exchange MEX files in the MATLAB environment of realizing invoke other language program, through Key words:MATLAB; C; MAT files; MEX files; MATLAB calculation engine ; MATLAB Compiler; MCC and MATCOM; Mixed programming technology
II
学 士 学 位 论 文
BACHELOR ’S THESIS 目 录
中文摘要 .......................................................................................................................I ABSTRACT ..................................................................................................................I 引言 .............................................................................................................................. 1 1. MATLAB .................................................................................................................. 1 1.1 MATLAB简介 ................................................................................................. 1 1.2 MATLAB的语言特点 ..................................................................................... 1 2. C 语言...................................................................................................................... 3 2.1 C语言简介 ....................................................................................................... 3 2.2 C语言特点 ....................................................................................................... 4 3. 混合编程的实现方式 ............................................................................................. 4 3.1 MAT文件........................................................................................................ 5 3.2 MEX文件 ....................................................................................................... 8 3.3 MATLAB计算引擎...................................................................................... 11 3.4 MATLAB编译器.......................................................................................... 13 3.5 MCC ................................................................................................................ 13 3.6 MATCOM ....................................................................................................... 16 4. C语言MEX文件的实现 ...................................................................................... 17 4.1 C语言MEX文件的编写............................................................................. 17 4.2 编译器的配置................................................................................................. 20 4.3 C语言MEX文件的编译............................................................................. 20 4.4 举例说明C的 MEX源程序的编写和调用过程 ......................................... 20 5. 结语 ....................................................................................................................... 24 参考文献 .................................................................................................................... 26
III
学 士 学 位 论 文
BACHELOR ’S THESIS 致 谢 .......................................................................................................................... 28
IV