www.gusucode.com > rmidemos工具箱matlab源码程序 > rmidemos/slvnvdemo_mfile_traceability.m
%% Traceability Associations for MATLAB File Contents % This example shows how to create and manage traceability associations for % MATLAB(R) code lines in MATLAB files, using the Requirements Management % Interface (RMI). This is similar to creating traceability associations % for MATLAB code lines in MATLAB Function blocks in Simulink(R) models, as % shown in the example <matlab:showdemo('slvnvdemo_matlab_traceability') % Traceability with MATLAB Code Lines in Simulink>. % % You can create traceability associations with all document types % supported by the RMI, including bidirectional linking with Microsoft(R) % Word and Microsoft(R) Excel documents. % % Use traceability associations for MATLAB files when, for example, your % MATLAB algorithm is explained in an external Word document, your MATLAB % computation relies on data loaded from an external Excel file, or your % MATLAB code implements test cases for Simulink models. % % Copyright 2013 The MathWorks, Inc. %% Create Traceability Associations Between Code Lines in Different MATLAB Files % Open the |<matlab:edit('sudoku_solver') sudoku_solver>| example script. % Notice the |sudoku_default()| call at % <matlab:rmicodenavigate('sudoku_solver','735515.1') line 24>. % MATLAB supports navigation from the call site to the called function implementation. % To open the |sudoku_default()| function in the MATLAB Editor, right-click % on the function call text |suduko_default|. From the context menu, select _Open "sudoku_default"_. % % Now suppose you want to point from |sudoku_default()| function contents % back to the call site without adding comments to MATLAB files. To do % this, create a traceability association between the two files. % % * Near the top of % <matlab:edit('sudoku_default') sudoku_default> function code, select the % text |suduko_solver|. Right-click on the selected text. % * In the context menu, select *Requirements Traceability* > *Open % Link Editor*. % % <<mldemo_link_editor_menu.png>> % % * In the Link Editor dialog box, click *New*. % * For *Document type*, select |MATLAB|. % * In the MATLAB Editor, switch to the <matlab:edit('sudoku_solver') % sudoku_solver.m file>. Select the line that says |<matlab:rmicodenavigate('sudoku_solver','735515.1') current = % sudoku_default()>|. % * In the Link Editor, click *Use current*. % % <<mldemo_link_editor_dlg.png>> % % In the *Document* field, _sudoku_solver_ appears. % % * Click *OK*. % % In the <matlab:edit('sudoku_default') sudoku_default.m file>, notice orange highlighting on the line you previously selected. % % * Right-click on the highlighted line. In the context menu, select *Requirements Traceability* > *1. current = sudoku_default()*. % % <matlab:edit('sudoku_solver') sudoku_solver> file comes to the front % with the call site highlighted. % % <<mldemo_link_highlighted.png>> % % If you close |sudoku_default.m|, a dialog box appears with options to save or discard the traceability data changes you made. % To avoid writing in your MATLAB installation directory, do not save % changes. Click *Discard*. % % <<mldemo_save_links_dlg.png>> % %% Save Traceability Associations for MATLAB Code Lines % When you create or modify traceability associations for MATLAB code % lines, you do not modify the MATLAB files themselves. The RMI % saves traceability data in separate files. The file path and file name of % a traceability data file matches its corresponding MATLAB code file, % but the file extension for a traceability data file is |.req|. You cannot % modify traceability data for a |.m| file if its corresponding |.req| file % is read-only. % % In the previous section, you created traceability associations but did not % save them. Notice that the |sudoku_solver.req| file is read-only. % % To save your traceability associations, create your own writeable copies % of |sudoku_solver.m| and |sudoku_default.m|, then repeat the steps in the % previous section. % % After you have created traceability assocations, save your % traceability data changes in one of the following ways: % % # Save your modified writable |.m| file. The corresponding |.req| file is % also saved. % # To save traceability data without resaving |.m| file, from the % *Requirements Traceability* context menu, select *Save Links*. % % <<mldemo_save_links_menu.png>> % % # If you try to close a |.m| file with unsaved traceability data changes, % a dialog box appears with options for you to save or discard your % changes. Click *Save*. % %% Create Traceability Associations from MATLAB Code Lines to External Documents % The example problem in |sudoku_default.m| was copied from the Wikipedia % page http://en.wikipedia.org/wiki/Sudoku. % % To associate this URL with code in the MATLAB file: % % * In the MATLAB Editor, open <matlab:edit('sudoku_default') sudoku_default>. % * At line 5, in the code comments, right-click on |Wikipedia|. % * In the context menu, select *Requirements Traceability* > *Open Link Editor*. % * In the Link Editor dialog box, click *New*. % * In the *Document* box, enter _http://en.wikipedia.org/wiki/Sudoku_. % * In the *Description* box, enter _Wikipedia article on Sudoku_. % * Click *OK*. % In |sudoku_default.m|, the line containing |Wikipedia| is % highlighted. % * Right-click the highlighted code. In the context menu, select *Requirements Traceability* % > *1. "Wikipedia article on Sudoku"*. This opens the % webpage in the web browser. % % <<mldemo_web_page.png>> % %% Create Traceability Associations from External Documents to MATLAB Code Lines % You can establish bidirectional links with Microsoft Word and Excel, % with IBM Rational DOORS, with Simulink model objects, and any % custom-defined document type that implements bidirectional linking. % % For this step of our example, you need a writable Microsort Word % document to link with (Word uses embedded _bookmarks_ as link targets). % Please open the included % |<matlab:open('sudoku_requirements.docx') sudoku_requirements.docx>| and % resave with a modified name, for example, |sudoku_requirements_writeable.docx|. % % <<settings_2way.png>> % % Make sure your user settings are configured for bidirectional linking % by selecting *Modify destination for bidirectional linking* % in the *Selection Linking* tab of the <matlab:rmi_settings_dlg() Requirements Settings dialog box>, % or by executing the following command: % % >> rmipref('BiDirectionalLinking', true) % % * Open |sudoku_requirements_writeable.docx|. % * Select the line that says % <matlab:rmi.navigate('linktype_rmi_word','sudoku_requirements_writeable.docx','@NoDigitTwiceInSameRow','') No digit should appear twice in same row>. % * In the MATLAB Editor, open <matlab:edit('sudoku_solver') sudoku_solver.m>. % * In the subfunction called <matlab:rmicodenavigate('sudoku_solver','735515.2') putDigit()>, % select the corresponding statement: % |<matlab:rmicodenavigate('sudoku_solver','735515.3') if any(current(row,:)==digit)>|. % * Right-click on your selection. In the context menu, select *Requirements Traceability* % > *Link to Selection in Word*. % % In the MATLAB Editor, orange highlighting appears on the linked code % lines. % % In the Word document, a navigation icon is inserted next to the % corresponding requirement description. % % * To navigate from the requirement description to the associated code, % in the Word document, click the navigation icon. % % In the MATLAB Editor, the associated code is highlighted. % % <<mldemo_two_way.png>> % %% More Things to Try with Same Example Files % % # Use the steps in the previous section to link all requirements in your copy of % |sudoku_requirements_writeable.docx| to corresponding lines in % <matlab:open('sudoku_solver.m') sudoku_solver.m>. % # Use the *Link Editor* dialog box to create traceability associations % between the two URLs in lines 10-13 of <matlab:open('sudoku_solver.m') sudoku_solver.m> with the % corresponding web pages. % %% Review Requirements Traceability Associations % Besides the background highlighting in the code pane, linked locations % are indicated in the right-hand-side message panel. You can hover over % the orange indicator to view the link labels, click to scroll % to the linked range, or click *Edit Links* to open the *Link Editor* dialog box. % % <<mldemo_link_markers.png>> % % When the Simulink Verification and Validation license is available, the % RMI supports Requirements Traceability report generation. To generate % a report for a single MATLAB file, use the |rmi('report', M_FILE_PATH)| % command: % % >> rmi('report', 'L:\Work\rmidemos\sudoku_default.m') % % To generate reports for all MATLAB files in the current Simulink Project, % enter the following command: % % >> rmi('projectreport') % % <<mldemo_req_report.png>> % %% When MATLAB Files Are Renamed % If you save a |.m| file with traceability data to a new name or to a new % location, the corresponding |.req| file is duplicated accordingly. % % Traceability associations from this |.m| file to other MATLAB files or % external documents remain valid. Traceability associations to this |.m| % file from external documents might become stale. % displayEndOfDemoMessage(mfilename)