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

    %% Configure Standard Math Library for Target System 
% Specify standard library extensions that the code 
% generator uses for math operations. When you generate code for a new model 
% or with a new configuration set object, the code generator uses the 
% ISO(R)/IEC 9899:1999 C (C99 (ISO)) library by default. For preexisting models and
% configuration set objects, the code generator uses the library specified
% by the *Standard math library* parameter.
% 
% If your compiler supports the ISO(R)/IEC 9899:1990 (C89/C90 (ANSI)) or 
% ISO/IEC 14882:2003(C++03 (ISO)) math library extensions, you can change 
% the standard math library setting. The C++03 (ISO) library is an option 
% when you select C++ for the programming language.
%
% The C99 library leverages the performance that a compiler offers over 
% standard ANSI C.  When using the C99 library, the code 
% generator produces calls to ISO C functions when possible.  For example, 
% the generated code calls the function  |sqrtf()|, which operates on 
% single-precision data, instead of  |sqrt()|. 
%
% To change the library setting, use the *Configuration Parameters>All
% Parameters>Standard math library* parameter.  The command-line equivalent
% is |TargetLangStandard|.
%% Generate and Inspect ANSI C Code
%
% 1. Open the example model |rtwdemo_clibsup|.
%
model='rtwdemo_clibsup';
open_system(model);
%%
% 2. Generate code.
%
rtwbuild(model)
%% 
% 3. Examine the code in the generated file |rtwdemo_clibsup.c|. Note that 
% the code calls the |sqrt| function. 
%
cfile = fullfile('rtwdemo_clibsup_grt_rtw', 'rtwdemo_clibsup.c');
rtwdemodbtype(cfile, ...
    'if (rtb_Abs2 < 0.0F) {', ...
    '/* End of Sqrt: ''<Root>/get_hypot1'' */', ... 
    1, 0);
rmdir('rtwdemo_clibsup_grt_rtw', 's');
rmdir('slprj', 's');
%% Generate and Inspect ISO C Code
%
% 1. Change the setting of *All Parameters>Standard math library* to |C99 (ISO)|. 
% Alternatively, at the command line, set |TargetLangStandard| to  |C99 (ISO)|.
%
set_param(model,'TargetLangStandard','C99 (ISO)'); 
%% 
% 2. Regenerate the code. 
%
rtwbuild(model)
%% 
% 3. Rexamine the code in the generated file |rtwdemo_clibsup.c|. Now the 
% generated code calls the function |sqrtf| instead of |sqrt|.
%
cfile = fullfile('rtwdemo_clibsup_grt_rtw', 'rtwdemo_clibsup.c');
rtwdemodbtype(cfile, ...
    'if (rtb_Abs2 < 0.0F) {', ...
    '/* End of Sqrt: ''<Root>/get_hypot1'' */', ... 
    1, 0);
%% Related Information
% * <docid:rtw_ref.bt7bn_r-1>
% * <docid:rtw_ug.f1116557>
%%
bdclose(model);
rtwdemoclean;