www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptimstore/getDataset.m

    function data = getDataset(optimstore, datasetName, inputNames)
%GETDATASET Retrieve data from a data set 
%   PTS = GETDATASET(OPTIMSTORE, DATASETNAME) returns all the data from the
%   specified data set. If the dataset cannot be found, DATA is returned as
%   empty.
%   
%   PTS = GETDATASET(OPTIMSTORE, DATASETNAME, INPUTNAMES) returns data from
%   the specified data set. Data is retrieved for the columns of the data
%   set with names that match those in INPUTNAMES. If the dataset cannot be
%   found, DATA is returned as empty.
%
%   Example: 
%   V = getdataset(optimstore, 'myDS', {'speed', 'afr'}) returns a
%   NPTS by 2 matrix, V. NPTS is the number of rows in the operating point
%   set labelled 'myDS', V(:, 1) is the data for the variable labelled
%   'speed', V(:, 2) is the data for the variable labelled 'afr'.
%
%  See also CGOPTIMOPTIONS/ADDOPERATINGPOINTSET.

%  Copyright 2000-2009 The MathWorks, Inc. and Ford Global Technologies, Inc.


if nargin < 2
    error(message('mbc:cgoptimstore:InvalidArguments'));
end

% Get dataset information from optimization
opts = getOptimOptions(optimstore.OptimRunner,'full');
info = getOperatingPointSets(opts);

if isv2mode(optimstore) 
    if nargin == 3
        % Reverse the order of inputs 2 and 3
        temp = inputNames;
        inputNames = datasetName;
        datasetName = temp;
    else
        % Put the input names into the third argument. Find the first data
        % set and use it. If there isn't one then error.
        if ~isempty(info)
            inputNames = datasetName;
            datasetName = info(1).label;
        else
            error(message('mbc:cgoptimstore:InvalidState2'));
        end
    end
end

if nargin < 3
    c = struct2cell(info);
    idx = strcmp(datasetName, c(1, :));
    if ~idx
        error(message('mbc:cgoptimstore:InvalidArgument4', datasetName));
    end
    inputNames = info(idx).vars;
end

data = getDatasetValues(optimstore.OptimRunner, inputNames, datasetName);