www.gusucode.com > simulinktestdemos 工具箱matlab源码程序 > simulinktestdemos/sltestUsingExcel.m
%% Importing Microsoft(R) Excel(R) Data % % Test a model using inputs stored in Microsoft Excel. % Copyright 2015 The MathWorks, Inc. %% % This example shows how to create a test case in the test manager % and use the Simulink(R) Root Inport Mapping tool to load mapping data % from a Microsoft(R) Excel(R) file. % The Root Inport Mapping tool supports Microsoft Excel spreadsheets % only for Microsoft Windows(R). % The example model used is a modified version of a shipping Simulink(R) example % that models the Automatic Transmission Controller. % For more information, see <matlab:open_system('sldemo_autotrans') sldemo_autotrans>. %% Create a Test File % Enter |sltestmgr| into the MATLAB command prompt to open the test manager. %% % Open example model |sltestExcelExample|. %% mdl = 'sltestExcelExample'; open_system(mdl); %% % Click *New* in the test manager toolstrip and select |Blank Test File|. % Save the file to a writable directory. % The test manager creates a test file with an empty baseline test case. %% % <<sltestCreatingNewTestFilePix.png>> %% % # To open the newly created test case, double-click it in the *Test Browser* pane. % # Under the *System Under Test* section, click the *Use current model* button. %% % <<sltestUseCurrentModelPix.png>> %% Navigate to Inputs Section % <<sltestScrollToInputsSectionPix.png>> %% Configure test case to use external inputs. % Navigate to the example folder directory: cd(fullfile(matlabroot,'toolbox','simulinktest','simulinktestdemos')); %% % Configure the test case to use external inputs from a data file. Select the *Load From File* check box. %% % <<sltestLoadFromFilePix.png>> %% Specify location of input data file. % For *Location*, click the *Browse* button and select |sltestExampleInputs.xlsx|. %% % <<sltestProvideFileLocationPix.png>> %% Selecting an Excel Sheet % Select the Excel sheet *Acceleration* from available sheets. %% % <<sltestSelectExcelSheetPix.png>> %% % The test case will import data to the MATLAB(R) base workspace from the specified file % and Excel sheet each time the test case is run. %% Root Inport mapping % Select |Port Order| from *Mapping Mode* menu. %% % <<sltestSelectMappingModePix.png>> %% Perform root inport mapping. % Click *Map Inputs* button to perform root inport mapping. %% % <<sltestMapInputsPix.png>> %% % The *Mapping Mode* controls the method used to map data from the Microsoft Excel sheet to % root-level Inport blocks in the model. To learn more about Inport Mapping, refer to the % <matlab:helpview(fullfile(docroot,'simulink','helptargets.map'),'Input_Mapping_Tool'); documentation>. %% % Check the mapping status and input string. The test case now uses inputs from the Excel sheet % mapped as specified in the Root Inport Mapping Tool. %% % <<sltestCheckMappingStatusPix.png>> %% close_system(mdl, 0); clear mdl; displayEndOfDemoMessage(mfilename)