Main Content

产生MEX功能s by Using theMATLABCoder应用程序

用于生成MEX函数的工作流MATLABCoder应用程序

行动 细节
1

设置MATLAB®CODER™项目。

设置MATLAB编码器项目
2

指定构建配置参数。放构建类型MEX

配置项目设置
3

建立项目。

构建MATLAB编码器项目

MATLAB编码器app is not supported inMatlab Online™。在MATLAB在线, 使用代码根命令。

使用MATLABCoder应用程序

此示例显示了如何使用MATLAB代码生成MEX函数MATLAB编码器应用程序。

Create the Entry-Point Function

在本地写入文件夹中,创建一个matlab文件,MCADD.M,,,,that contains:

functiony = mcadd(u,v)%#codegeny = u + v;

创建测试文件

In the same local writable folder, create a MATLAB file,mcadd_test。m,,,,that callsmcaddwith example inputs. The example inputs are scalars with typeint16

functiony = mcadd_test y = mcadd(int16(2),int16(3));

打开MATLABCoder应用程序

在MATLAB工具条上应用标签,下代码生成,,,,click theMATLAB编码器app icon.

该应用程序打开选择源文件页。

Specify Source Files

  1. 选择源文件页面,输入或选择入口点功能的名称mcadd

    该应用程序创建一个带有默认名称的项目mcadd.prj

  2. 点击Next至go to theDefine Input Types步。这app analyzes the function for coding issues and code generation readiness. If the app identifies issues, it opens the审查代码生成准备就绪您可以在其中查看和解决问题的页面。在此示例中,由于该应用没有检测到问题,因此它打开了Define Input Types页。

Define Input Types

Because C uses static typing, at compile time,MATLAB编码器must determine the properties of all variables in the MATLAB files. You must specify the properties of all entry-point function inputs. From the properties of the entry-point function inputs,MATLAB编码器can infer the properties of all variables in the MATLAB files.

指定测试文件mcadd_test。mthatMATLAB编码器用于自动定义类型andv

  1. 输入或选择测试文件mcadd_test。m

  2. 点击Autodefine Input Types

    测试文件,mcadd_test。m,调用入口点函数,mcadd,带有示例输入类型。MATLAB编码器infers that inputsandvINT16(1x1)

  3. 点击Next至go to the检查运行时间问题步。

检查运行时间问题

检查运行时间问题步骤从您的入口点功能中生成MEX文件,运行MEX函数并报告问题。此步骤是可选的。但是,执行此步骤是最好的做法。您可以检测和修复在生成的C代码中难以诊断的运行时错误。

  1. 打开检查运行时间问题dialog box, click the检查问题arrow

    该应用程序填充了测试文件字段mcadd_test,您用来定义输入类型的测试文件。

  2. 点击检查问题

    该应用程序生成MEX函数。它运行测试文件,替换电话mcaddwith calls to the MEX function. If the app detects issues during the MEX function generation or execution, it provides warning and error messages. Click these messages to navigate to the problematic code and fix the issue. In this example, the app does not detect issues.

  3. 点击Next至go to the产生Code步。

生成MEX功能

  1. 打开产生dialog box, click the产生arrow

  2. In the产生dialog box, set构建类型MEXandC.使用其他项目构建配置设置的默认值。

  3. 点击产生

    该应用显示代码生成成功。它显示页面左侧的源MATLAB文件和生成的输出文件。在Variables选项卡,它显示有关MATLAB源变量的信息。在Target Build Log选项卡,它显示构建日志,包括编译器警告和错误。

    MATLAB编码器构建项目,默认情况下会生成MEX函数,mcadd_mex,,,,in the current folder.MATLAB编码器also generates other supporting files in a subfolder called代码根/mex/mcaddMATLAB编码器你ses the name of the MATLAB function as the root name for the generated files. It creates a platform-specific extension for the MEX file. See命名约定

  4. 要查看代码生成报告,请单击查看报告

  5. 点击Next打开Finish Workflow页。

Review the Finish Workflow Page

Finish Workflow页面表示代码生成成功。它提供了一个项目摘要并链接到生成的输出。

配置项目设置

dia打开项目设置log box:

  1. 打开产生dialog box, click the产生arrow

  2. 点击更多设置

要更改项目设置,请单击包含要更改的设置的选项卡。例如,更改Saturate on integer overflow设置,单击速度标签。

MEX functions use a different set of configuration parameters than libraries and executables. When you change the output type fromMEX功能源代码静态库,,,,动态库, 或者可执行,,,,verify these settings.

Certain configuration parameters are relevant for both MEX and standalone code generation. If you enable any of these parameters when the output type isMEX功能,并且您也想对C/C ++代码生成使用相同的设置,您必须再次启用它C/C ++静态库,,,,C/C ++动态库,,,,andC/C ++可执行

也可以看看

Build aMATLABCoder项目

使用指定设置构建项目产生Code页面,单击产生。As theMATLAB编码器App构建一个项目,它显示构建进度。构建完成后,该应用程序提供有关构建的详细信息Target Build Log标签。

If the code generation report is enabled or build errors occur, the app generates a report. The report provides detailed information about the most recent build, and provides a link to the report.

要查看报告,请单击查看报告link. The report provides links to your MATLAB code and generated C/C++ files and compile-time type information for the variables in your MATLAB code. If build errors occur, the report lists errors and warnings.

也可以看看

Related Topics