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

    %% Tune Phase Parameter of Sine Wave Block During Code Execution
% Under certain conditions, you cannot configure the *Phase* parameter of a Sine Wave block to appear
% in the generated code as a tunable global variable (for more information,
% see the block reference page). This example shows how to generate code so
% that you can tune the phase during execution.
%
% Create the model |ex_phase_tunable|:
open_system('ex_phase_tunable')
%%
% Set *Default parameter behavior* to |Tunable| so that the parameters of
% the Sine Wave block appear in the generated code as tunable fields of the
% global parameter structure.
set_param('ex_phase_tunable','DefaultParameterBehavior','Tunable')
%%
% Generate code from the model.
rtwbuild('ex_phase_tunable')
%%
% In the code generation report, view the file |ex_phase_tunable.c|. The
% code algorithm in the model |step| function calculates the Sine Wave
% block output. The parameters of the block, including *Phase*, appear in the code as
% tunable structure fields.
file = fullfile('ex_phase_tunable_grt_rtw','ex_phase_tunable.c');
rtwdemodbtype(file,'/* Outport: ''<Root>/Out1'' incorporates:',...
    'ex_phase_tunable_P.SineWave_Bias;',1,1)
%%
% During code execution, you can assign new values to the structure field that
% corresponds to the *Phase* parameter.