www.gusucode.com > mbcdemos 工具箱 matlab 源码程序 > mbcdemos/mbcDataCmdLine.m
%% Loading and Modifying Data % This example shows how to load and modify data using Model-Based Calibration Toolbox(TM) % command-line interface. Data can be loaded from files (Excel(R) files, MATLAB(R) files, text % files) and from the MATLAB(R) workspace. You can define new variables, apply filters to remove % unwanted data, and apply test notes to filtered tests. % Copyright 2007-2012 The MathWorks, Inc. %% Load Data from Excel(R) % Load data from holliday.xls. dataFile = fullfile( matlabroot, 'toolbox', 'mbc', 'mbctraining', 'holliday.xls' ); data = mbcmodel.CreateData( dataFile ); get( data ) data.SignalNames %% Plot Data % You can use the SignalName as an input to the Value method. % Plot the first 5 tests. x = zeros(10,5); y = zeros(10,5); name = cell(1,5); % Collect the data as columns to pass to plot. for tn = 1:5 x(:,tn) = data.Value( 'spark', tn ); y(:,tn) = data.Value( 'tq', tn ); name{tn} = sprintf( 'Test %d', tn ); end plot( x, y, 'x-' ); legend( name ); grid on xlabel( sprintf( '%s [%s]', 'spark', data.SignalUnits{5} ) ); ylabel( sprintf( '%s [%s]', 'tq', data.SignalUnits{5} ) ); title( 'tq vs. spark' ); %% Remove Outliers and Problem Tests % Add a filter to keep tests where the mean torque is greater than 10. % A filter is a constraint on the data set you can use to exclude some % tests (test filter) or records (filter). % You must call BeginEdit before making changes. The data is only updated % when you call CommitEdit. numberOfTestsBefore = data.NumberOfTests; data.BeginEdit; data.AddTestFilter( 'mean(tq)>10' ); data.CommitEdit; numberOfTestsAfter = data.NumberOfTests; fprintf( 'Removed %d tests.\n', numberOfTestsBefore-numberOfTestsAfter ); %% Add New Variable % You can add new variables to the data set. data.BeginEdit; data.AddVariable( 'POWER=tq*n' ); data.CommitEdit; signalNamesBefore = data.SignalNames % POWER is now in the list of SignalNames, and can be used to define other % new variables. data.BeginEdit; data.AddVariable( 'POWER_SQUARED=POWER^2' ); data.CommitEdit; signalNamesAfter = data.SignalNames %% Apply a Filter % Add a filter to keep only records where speed is greater than 1000. numberOfRecordsBefore = data.NumberOfRecords; data.BeginEdit; data.AddFilter( 'n>1000' ); data.CommitEdit; numberOfRecordsAfter = data.NumberOfRecords; fprintf( 'Removed %d records.\n', numberOfRecordsBefore-numberOfRecordsAfter ); displayEndOfDemoMessage(mfilename)