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

    function [status,msg] = checkInterpolation(DS,optim)
%CHECKINTERPOLATION check whether interpolation is well-defined
%
% [status,msg] = checkInterpolation(DS,optim)

%  Copyright 2009-2010 The MathWorks, Inc. 


status = 0;
msg = '';
if isAppPointOptim(DS) 
    % fit thinplate spline interpolant to operating point variables
    [InputData, pAllInp] = getinitialvaluedata(optim);
    [~,loc ] = ismember(DS.OpPointVariables,pAllInp);
    if size(InputData{loc(1)},2)~=size(InputData{loc(2)},2) || size(InputData{loc(1)},2)==1
        % operating point values must be the same size and not scalar
        status = 2;
        msg = 'The optimization operating point variables must be vectors with the same size.';
    else
        % try interpolation to determine if this is OK
        Xop = cat(1,InputData{loc})';
        if ~all(DS.UseMode)
            [~,InterpOK] = cgThinplateSpline.fit( Xop );
            if ~InterpOK
                status = 2;
                msg = 'The optimization operating point variables must be unique and not on a line.';
            end
        end
        if ~isnull(DS.ModeVariable) && any(DS.UseMode)
            % interpolation is performed for each mode
            [~,locMode ] = ismember(DS.ModeVariable,pAllInp);
            dsvars = [DS.OpPointVariables,DS.ModeVariable];
            Mode = InputData{locMode}(:);
            for i= find(DS.UseMode)
                % need to check full modal interpolation as there may be
                % modes for which the interpolation is not defined but is
                % not required
                [~,locDS] = ismember(dsvars,   get(DS.Datasets(i).info,'ptrlist'));
                D = get(DS.Datasets(i).info,'Data');
                InterpOK = cgThinplateSpline.interpByMode( Xop, Mode ,D(:,locDS(1:2)),D(:,locDS(end)) );
                if ~InterpOK
                    status = 2;
                    msg = 'The optimization operating point variables must be unique and not on a line for each mode.';
                end
            end
        end
    end
end