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).
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.
Simulate the model and review the results (displayed automatically).
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.
Configure and build the model using Embedded Coder.
### Starting build procedure for: RadarTracker ### Successful completion of build procedure for: RadarTracker Build Summary Top model targets built: Model Action Rebuild Reason ============================================================================================= RadarTracker Code generated and compiled Code generation information file does not exist. 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 18.573s
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.
Close the model and cleanup.
bdclose(model) rtwdemoclean; cd(currentDir)