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

    function [ok, report] = testfunction(obj, idx)
%TESTFUNCTION Test an optimization function
%
%  [OK, REPORT] = TESTFUNCTION(OBJ, IDX) tests the function at index IDX to
%  check whether it can run.  If OK is false, REPORT will contain an Nx2
%  cell array containing pairs of headings and further information on the
%  problems encountered.

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

nFuncs = length(obj.FunctionNames);
% Check index is OK
if (numel(idx) ~= 1) || (idx > nFuncs) || (idx < 1)
    error(message('mbc:cgoptimfuncs:InvalidArgument'))
end

fileexists = pfindfunction(obj.FunctionNames{idx});
if fileexists
    optimobj = cgoptim;
    [~, ok, report] = setfunctionfile(optimobj, obj.FunctionNames{idx});
else
    ok = false;
    report = {'Function not found', ...
            ['The function specified was not found on MATLAB''s search path.  ', ...
                'Check that you have added the function''s location to the MATLAB ', ...
                'path by looking at the Set Path tool. In MATLAB, on the Home tab, ',...
                'in the Environment section, select Set Path.']};
end