www.gusucode.com > simulinkcoder 案例源码程序 matlab代码 > simulinkcoder/GenerateCodeUsingSimulinkCoderExample.m

    %% Generate Code Using Simulink(R) Coder(TM) 
% This example shows how to select a target for a Simulink(R) model,
% generate C code for real-time simulation, and view generated files.
%
% The model represents an 8-bit counter that feeds a triggered subsystem
% that is parameterized by constant blocks |INC|, |LIMIT|, and |RESET|.  |Input| and
% |Output| represent I/O for the model. The |Amplifier| subsystem amplifies the
% input signal by gain factor |K|, which updates when signal |equal_to_count| is |true|.
%
% Copyright 2008-2015 The MathWorks, Inc.

%%
% *1.* Open the model. For example, type the following commands at the MATLAB(R) command prompt.

model='rtwdemo_rtwintro';
open_system(model)

%%
% *2.*	Open the Configuration Parameters dialog box from the model editor
% by clicking *Simulation > Configuration Parameters*. 
%
% Alternately, type the following commands at the MATLAB(R) command prompt.

cs = getActiveConfigSet(model);
openDialog(cs);

%%
% *3.* Select the *Code Generation* node.
%
% <<../rtw_main_page_grt.png>>

%%
% *4.* In the *Target Selection* pane, click *Browse* to select a target.
% 
% You can generate code for a particular target environment or purpose.
% Some built-in targeting options are provided using system target files,
% which control the code generation process for a target.
%
% <<../rtw_browse_stf_button_grt.png>>
%
% <<../rtw_target_selection_grt.png>>

%%
% *5.* Select the *Generic Real-Time (GRT)* target and click *Apply*.
%
% Optionally, in the *Code Generation Advisor* pane set the *Select
% objective* field to *Execution efficiency* or *Debugging*.  Then click
% *Check model...* to identify and systematically change parameters to meet
% your objectives.

%%
% *6.* In the model window, press *Ctrl+B* to generate code.
%
% <<../rtw_build_button_grt.png>>

%%
% *7.* View the code generation report that appears.
%
% The report includes links to model files such as |rtwdemo_rtwintro.c| and
% associated utility and header files.
%
% <<../rtw_report_grt.png>>
%

%%
% The figure below contains a portion of |rtwdemo_rtwintro.c|
%
% <<../ag_rtwdemo_rtwintro_grtstep.png>>

%%
% *8.* Close the model.

bdclose(model)
rtwdemoclean;