www.gusucode.com > ecoder 案例源码程序 matlab代码 > ecoder/LinkGeneratedCodeToRequirementsExample.m
%% Link Generated Code to Requirements % Link generated code to model % object requirements. Using configuration parameters, you can specify whether % to include requirement descriptions as comments in the generated code. %% Open Model % Open the rtwdemo_requirements model. The model contains Simulink(R) and % Stateflow(R) objects with associated requirements. model='rtwdemo_requirements'; open_system(model); %% View Requirements % You can view requirements to model objects by using the object context menu. % Right-click an object and select *Requirements Traceability*. % To view the requirements, use these commands: % % 1. To view the requirements for the |DiscretePulseGenerator| block, open the Link Editor. clockblock='rtwdemo_requirements/clock'; clockblockh=get_param(clockblock,'handle'); rmi('edit',clockblockh); %% % 2. To view the requirements, open the *Signal Builder* block. % sigbblock='rtwdemo_requirements/Signal Builder'; open_system(sigbblock) %% % 3. To view the requirements for the Stateflow(R) state, open the Link Editor. state=find(sfroot,'-isa','Stateflow.State','-and','Tag','req_state'); rmi('edit',state.id); %% % 4. To view the requirements for the Stateflow transition, open the Link Editor. trans=find(sfroot,'-isa','Stateflow.Transition','-and','Tag','req_trans'); rmi('edit',trans.id); %% % 5. To view the requirements for the Stateflow function, open the Link Editor. func=find(sfroot,'-isa','Stateflow.Function','-and','Tag','req_function'); rmi('edit',func.id); %% % Close the open windows. close_system(sigbblock); %% Set Configuration Parameters % % Open the Configuration Parameters dialog box *Code Generation > Comments* % pane. View the configuration parameter settings. model = bdroot; slCfgPrmDlg(model,'Open'); slCfgPrmDlg(bdroot,'TurnToPage','Comments'); %% Generate Code % % Generate code for the model. rtwbuild('rtwdemo_requirements') %% % In the generated code, view the comments containing the requirements. rtwdemodbtype('rtwdemo_requirements_ert_rtw/rtwdemo_requirements.c',... '/* Function for Chart:','return result;',1,0); %% See Also % * For requirement traceability, see % <matlab:helpview(fullfile(docroot,'slvnv','slvnv.map'),'managing_modeling_requirements'); Overview of the Requirements Management Interface> %% Close Model rtwdemoclean; close_system('rtwdemo_requirements',0);