Documentation

Build and Run a Program

这build process generates C code from a model, then compiles and links the generated program to create an executable image. To build and run a sample program, use the example modelSlexaircraftExample

  1. In the Command Window, enterSlexaircraftExampleto open the model.

  2. 将模型的副本保存到您的工作文件夹并命名myAircraftExample

  3. Open the Configuration Parameters dialog box by selecting模拟>模型配置参数。Set the following parameters.

    • SelectConfiguration Parameters>求解器。Enter the following parameter values for the求解器(some could already be set):

      • Start time:0.0

      • Stop time:60

      • Type:Fixed-step

      • 求解器:ode5 (Dormand-Prince)

      • 固定步长(基本样本时间):0.1

      • Treat each discrete rate as a separate task:Off

    • SelectConfiguration Parameters>Code Generation>Report, and select theCreate code generation report范围。此选项使构建过程在生成代码生成代码的代码报告后显示myAircraftExamplemodel.

    • SelectConfiguration Parameters>Code Generation>Interface。为了共享代码放置parameter, selectShared location。This option causes generated code for utilities to be placed at a shared location within theslprjfolder in the代码生成文件夹(Simulink).

    • Clear theConfiguration Parameters>Code Generation>Interface>Advanced parameters>Classic call interface选项。

    • Set theConfiguration Parameters>Code Generation>Interface>Advanced parameters>Single output/update function选项。

    ClickApply好的

  4. With the model open, initiate code generation and the build process for the model by using any of the following options:

    • 点击Build Modelbutton.

    • PressCtrl+b

    • SelectCode>C/C++ Code>Build Model

    • Invoke thertwbuildcommand from the MATLAB®command line.

    • Invoke theslbuildcommand from the MATLAB command line.

    有关代码生成和编译的一些消息出现在MATLAB Command Window. The initial message is:

    # # #开始构建过程模型:myAircraftExample

    这contents of many of the succeeding messages depends on your compiler and operating system. The final messages include:

    ### Created executable slexAircraftExample.exe ### Successful completion of build procedure for model: myAircraftExample ### Creating HTML report file myAircraftExample_codegen_rpt.html

    代码生成文件夹现在包含可执行文件,myaircraftExample.exe(Microsoft®视窗®platforms) ormyAircraftExample(unix®platforms). In addition, the build process has created anslprjfolder and amyAircraftExample_grt_rtwfolder in the代码生成文件夹(金宝appSimulink)。

    不te

    这build process displays a code generation report after generating the code for themyAircraftExamplemodel. SeeReport Generationfor more information about how to create and use a code generation report.

  5. To observe the contents of the working folder after the build, type thedir或者LS从命令窗口命令。

    >>dir。myaircraftExample.exemyAircraftExample_grt_rtw .. myAircraftExample.slx slprj
  6. To run theexecutable from the Command Window, type!slexAircraftExample。这!character passes the command that follows it to the operating system, which runs the standaloneSlexaircraftExampleprogram.

    >>!myAircraftExample**启动模型** **创建myaircraftExample.mat **
  7. To seethe files created in the build folder, use thedir或者LScommand again. The exact list of files produced varies among MATLAB platforms and versions. Here is a sample list from a Windows platform.

    >>dir myaircraftExample_grt_rtw。rt_main.obj myAircraftExample_data.c .. rtmodel.h myAircraftExample_data.obj buildInfo.mat rtw_proj.tmw myAircraftExample_private.h codeInfo.mat myAircraftExample.bat myAircraftExample_ref.rsp defines.txt myAircraftExample.c myAircraftExample_types.h html myAircraftExample.h modelsources.txt myAircraftExample.mk rt_logging.obj myAircraftExample.obj

Tip

For UNIX platforms, run the executable in the Command Window with the syntax!.//executable_name。If preferred, run the executable from an OS shell with the syntax./executable_name。For more information, seeRun External Commands, Scripts, and Programs(MATLAB)。

相关话题

这个话题有帮助吗?