Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Loading and Modifying Data

This example shows how to load and modify data using Model-Based Calibration Toolbox™ command-line interface. Data can be loaded from files (Excel® files, MATLAB® files, text files) and from the MATLAB® workspace. You can define new variables, apply filters to remove unwanted data, and apply test notes to filtered tests.

Load Data from Excel®

Load data from holliday.xls.

dataFile = fullfile( matlabroot, 'toolbox', 'mbc', 'mbctraining', 'holliday.xls' );
data = mbcmodel.CreateData( dataFile );
get( data )
data.SignalNames
               Name: 'holliday'
    NumberOfRecords: 270
      NumberOfTests: 27
     RecordsPerTest: [1x27 double]
         IsEditable: 1
      IsBeingEdited: 0
              Owner: []
        SignalNames: {7x1 cell}
        SignalUnits: {7x1 cell}
            Filters: [0x0 struct]
        TestFilters: [0x0 struct]
      UserVariables: [0x0 struct]


ans = 

    'afr'
    'egr'
    'load'
    'n'
    'spark'
    'logno'
    'tq'

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 );
Removed 9 tests.

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
signalNamesBefore = 

    'afr'
    'egr'
    'load'
    'n'
    'spark'
    'logno'
    'tq'
    'POWER'


signalNamesAfter = 

    'afr'
    'egr'
    'load'
    'n'
    'spark'
    'logno'
    'tq'
    'POWER'
    'POWER_SQUARED'

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 );
Removed 38 records.
Was this topic helpful?