This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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.xlsx.

dataFile = fullfile( matlabroot, 'toolbox', 'mbc', 'mbctraining', 'holliday_data.mat' );
data = mbcmodel.CreateData( dataFile );
get( data )
               Name: 'holliday_data'
    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 =

  7x1 cell array

    {'afr'  }
    {'egr'  }
    {'load' }
    {'n'    }
    {'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 );
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.AddTestFilter( 'mean(tq)>10' );
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.AddVariable( 'POWER=tq*n' );
signalNamesBefore = data.SignalNames
% POWER is now in the list of SignalNames, and can be used to define other
% new variables.
data.AddVariable( 'POWER_SQUARED=POWER^2' );
signalNamesAfter = data.SignalNames
signalNamesBefore =

  8x1 cell array

    {'afr'  }
    {'egr'  }
    {'load' }
    {'n'    }
    {'tq'   }

signalNamesAfter =

  9x1 cell array

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

Apply a Filter

Add a filter to keep only records where speed is greater than 1000.

numberOfRecordsBefore = data.NumberOfRecords;
data.AddFilter( 'n>1000' );
numberOfRecordsAfter = data.NumberOfRecords;
fprintf( 'Removed %d records.\n', numberOfRecordsBefore-numberOfRecordsAfter );
Removed 38 records.
Was this topic helpful?