www.gusucode.com > rtwdemos 工具箱matlab源码程序 > rtwdemos/ForLoopFusion.m
%% Optimizing FOR Loops by Fusing Multiple FOR Constructs % This example shows how the FOR loops can be optimized % through fusion in the generated code. % Copyright 2010-2014 The MathWorks, Inc. %% Overview % The FOR constructs in the generated code represent a variety of modeling constructs such as matrix % type signal, Iterator blocks and so on. % % Using data dependency analysis, this optimization fuse FOR constructs % to reduce static code size and runtime branching % % The benefits of optimizing the generated code are: % % * Reducing the ROM and RAM consumption. % * Improving the execution speed. %% Review The Switch Blocks and FOR loop in the EML block % Consider the model <matlab:rtwdemo_forloop rtwdemo_forloop>. % In this model, there are multiple FOR loops for the matrix type signal assignment and references % which are fused into a single FOR loop. model = 'rtwdemo_forloop'; open_system(model); %% Generate Code With This Optimization % In the model, since there is no data dependency across iteration among all the FOR % loops in the modeling domain, all loops are fused into one loop. % % Therefore, there is only a single FOR loop in the generated code currentDir = pwd; [tempDir,cgDir] = rtwdemodir(); %% % Build the model using Embedded Coder. rtwbuild(model) %% % A portion of |rtwdemo_forloop.c| is listed below. cfile = fullfile(cgDir,'rtwdemo_forloop_grt_rtw','rtwdemo_forloop.c'); rtwdemodbtype(cfile,'/* Model step', '/* Model initialize', 1, 0); %% % Close the model and cleanup. bdclose(model) rtwdemoclean; cd(currentDir); rmdir(tempDir,'s'); displayEndOfDemoMessage(mfilename)