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
。
In the Command Window, enter
SlexaircraftExample
to open the model.将模型的副本保存到您的工作文件夹并命名
myAircraftExample
。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范围。此选项使构建过程在生成代码生成代码的代码报告后显示
myAircraftExample
model.SelectConfiguration Parameters>Code Generation>Interface。为了共享代码放置parameter, select
Shared location
。This option causes generated code for utilities to be placed at a shared location within theslprj
folder 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和好的。
With the model open, initiate code generation and the build process for the model by using any of the following options:
有关代码生成和编译的一些消息出现在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 anslprj
folder and amyAircraftExample_grt_rtw
folder in the代码生成文件夹(金宝appSimulink)。不te
这build process displays a code generation report after generating the code for the
myAircraftExample
model. SeeReport Generationfor more information about how to create and use a code generation report.To observe the contents of the working folder after the build, type the
dir
或者LS
从命令窗口命令。>>dir。myaircraftExample.exemyAircraftExample_grt_rtw .. myAircraftExample.slx slprj
To run theexecutable from the Command Window, type
!slexAircraftExample
。这!
character passes the command that follows it to the operating system, which runs the standaloneSlexaircraftExample
program.>>!myAircraftExample**启动模型** **创建myaircraftExample.mat **
To seethe files created in the build folder, use the
dir
或者LS
command 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)。