www.gusucode.com > ecoder 案例源码程序 matlab代码 > ecoder/AircraftPositionRadarModelExample.m
%% Aircraft Position Radar Model % This model shows the code generated for a Simulink model containing a % MATLAB script. % % The model contains an Extended Kalman Filter that estimates aircraft % position from radar measurements. The MATLAB script % rtwdemo_eml_aero_radar.m contains data for running the model. The % estimated and actual positions are saved to the workspace and are plotted % at the end of the simulation by the program rtwdemo_aero_radplot (called % from the simulation automatically). % Copyright 2009-2012 The MathWorks, Inc. %% Review and Simulate the Model % In this section you should review the model and perform a simulation. %% % Open the Simulink model. model='rtwdemo_eml_aero_radar'; open_system(model) rtwdemo_eml_aero_radar([],[],[],'compile'); rtwdemo_eml_aero_radar([],[],[],'term'); %% % Open the MATLAB Function block |RadarTracker| in the MATLAB Editor. open_system([model,'/RadarTracker']) %% % <<../KalmanFilterMATLABScript.jpg>> %% % Simulate the model and review the results (displayed automatically.) sim(model) %% Generate Code for the Model % In this section you will generate code for the Kalman Filter portion of % the model using the subsystem build functionality provided by Simulink % Coder. In the first build, the model is configured to generate code % using Simulink Coder. In the second build, the model is configured to % generate code using Embedded Coder. % Create a temporary folder (in your system's temporary folder) for the % build and inspection process. currentDir = pwd; [~,cgDir] = rtwdemodir(); %% % Configure and build the model using Simulink Coder. rtwconfiguredemo(model,'GRT') rtwbuild([model,'/RadarTracker']) %% % Configure and build the model using Embedded Coder. rtwconfiguredemo(model,'ERT') rtwbuild([model,'/RadarTracker']) %% % A portion of |RadarTracker.c| is listed below. cfile = fullfile(cgDir,'RadarTracker_ert_rtw','RadarTracker.c'); rtwdemodbtype(cfile,'/* Model step', '/* Model initialize', 1, 0); %% % You can view the entire generated code in a detailed HTML report, with % bi-directional traceability between model and code. web(fullfile(cgDir,'RadarTracker_ert_rtw','html','RadarTracker_codegen_rpt.html')) %% % Close the model and cleanup. bdclose(model) rtwdemoclean; cd(currentDir)