www.gusucode.com > mbcdemos 工具箱 matlab 源码程序 > mbcdemos/mbcLocalDoeCmdLine.m

    %% Local Designs
% This example shows how to use the command-line functionality to generate local designs at each
% global operating point. This particular example shows how you can produce local maps for a diesel
% engine calibration.

% Copyright 2007-2014 The MathWorks, Inc.

%% Create Project and Test Plan
% Speed (N) and fuel (F) are global inputs. 
% Injection (soi), fuel pressure (fuelpress), variable geometry turbo rack
% position (grackmea) and exhaust gas recirculation (EGR) are local inputs.
project = mbcmodel.CreateProject('DieselMulti');

% Define Inputs for test plan
LocalInputs = mbcmodel.modelinput('Symbol',{'S','P','G','E'},...
    'Name',{'soi','fuelpress','grackmea','egrlift'},...
    'Units',{'deg','MPa','ratio','mm'},...
    'Range',{[-9 3],[60 160],[0.2 0.9],[0.5 5]});
GlobalInputs = mbcmodel.modelinput('Symbol',{'N','F'},...
    'Name',{'measrpm','basefuelmass'},...
    'Units',{'rpm','mg/stroke'},...
    'Range',{[1600 2200],[20 200]});
% create test plan
TP = CreateTestplan( project, {LocalInputs,GlobalInputs} );

%% Global Design
% Generate a 15 point Latin Hypercube Sampling (LHS) design for the global
% inputs.
globalDesign = TP.CreateDesign(2, 'Type', 'Latin Hypercube Sampling');
% Fuel constraint:  Maximum 200 at 1600 rpm, 175 at 2200 rpm
C = globalDesign.CreateConstraint('Type','1D Table');
% set up the 1D Table constraint
C.InputFactor = 'N';
C.Breakpoints = [1600 2000];
C.TableFactor = 'F';
C.Table = [200 175];
% assign constraint to design
globalDesign.Constraints = C;
% generate a 15 point design
globalDesign = Generate(globalDesign, 15);
% set as best design in test plan
TP.BestDesign{2} = globalDesign;

%% Create a Local Design for Each Global Point
% For each global point, adjust limits for fuel pressure and grackmea, and 
% generate a 30 point LHS design.

% create a local design
localDesign = TP.CreateDesign(1,'Type','Latin Hypercube Sampling');
localDesignGenerator = localDesign.Generator;
localDesignGenerator.NumberOfPoints = 30;
DList = mbcdoe.design.empty( 0, 1);
for i = 1:globalDesign.NumberOfPoints;
    GlobalPoint = globalDesign.Points(i,:);
    speed = GlobalPoint(1);
    % fuel pressure limits dependent on speed
    f = (speed-1600)/(2200-1600);
    % note because you use the Limits property to specify the input range
    % you get LHS designs with exactly 30 points.
    localDesignGenerator.Limits(2,:) = (1-f)*[90 120] + f*[110 160];
    % grackmea limits dependent on speed
    localDesignGenerator.Limits(3,:) = (1-f)*[0.2 0.4] + f*[0.6 0.9];

    % set design properties and generate local design
    localDesign.Generator = localDesignGenerator;
    
    % Make design name which reflects the global point
    localDesign.Name = sprintf('Test %2d (%s=%4.0f,%s=%3.0f)', i,...
        GlobalInputs(1).Symbol,GlobalPoint(1),....
        GlobalInputs(2).Symbol,GlobalPoint(2));
    
    % Plot Design
    Scatter2D(localDesign);
    
    DList(i) = localDesign;
end

% assign list of local designs to test plan
TP.Designs{1} = DList;
% List of local designs
localDesigns = TP.Designs{1}

displayEndOfDemoMessage(mfilename)