В этом примере показано, как генератор кода оптимизирует сгенерированный код путем удаления кода, который не оказывает влияния на результаты расчетов. Эта оптимизация:
Скорость выполнения увеличений.
Уменьшает потребление ROM.
В модели rtwdemo_blockreduction, блок Gain значения 1.0 промежуточные блоки Inport и Outport.
model = 'rtwdemo_blockreduction';
open_system(model);

Создайте временную папку для сборки и инспекционного процесса.
currentDir=pwd; [~,cgDir]=rtwdemodir();
Создайте модель.
set_param(model,'BlockReduction','off'); rtwbuild(model)
### Starting build procedure for model: rtwdemo_blockreduction ### Successful completion of build procedure for model: rtwdemo_blockreduction
Вот код от rtwdemo_blockreduction.c.
cfile = fullfile(cgDir,'rtwdemo_blockreduction_ert_rtw','rtwdemo_blockreduction.c'); rtwdemodbtype(cfile, '/* Model step function */',... '/* Model initialize function */', 1, 0);
/* Model step function */
void rtwdemo_blockreduction_step(void)
{
/* Outport: '<Root>/Out1' incorporates:
* Gain: '<Root>/Gain'
* Inport: '<Root>/In1'
*/
rtwdemo_blockreduction_Y.Out1 = 1.0 * rtwdemo_blockreduction_U.In1;
}
Откройте диалоговое окно Configuration Parameters.
Выберите сокращение Block. Эта оптимизация включена по умолчанию.
Поочередно, используйте API командной строки, чтобы включить оптимизацию.
set_param(model,'BlockReduction','on');
rtwbuild(model)
### Starting build procedure for model: rtwdemo_blockreduction ### Successful completion of build procedure for model: rtwdemo_blockreduction
Вот оптимизированный код от rtwdemo_blockreduction.c.
cfile = fullfile(cgDir,'rtwdemo_blockreduction_ert_rtw','rtwdemo_blockreduction.c'); rtwdemodbtype(cfile, '/* Model step function */',... '/* Model initialize function */', 1, 0);
/* Model step function */
void rtwdemo_blockreduction_step(void)
{
/* Outport: '<Root>/Out1' incorporates:
* Inport: '<Root>/In1'
*/
rtwdemo_blockreduction_Y.Out1 = rtwdemo_blockreduction_U.In1;
}
Поскольку умножение входного сигнала на значение 1.0 не влияет на результаты расчетов, генератор кода исключает блок Gain из сгенерированного кода. Закройте модель и вымойтесь.
bdclose(model) rtwdemoclean; cd(currentDir)