www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptimrunner/private/pRunv2.m
function [mainOK, mainmsg, OK, freevals, msg, stats] = pRunv2(obj, DOWAITBAR, waitH) %PRUNV2 Run the optimization using version 2 interface. % % [MAINOK, MAINMSG, OK, FREEVALS, MSG, STATS] = PRUNV2(OBJ) runs the % optimization assuming the user-function is written for MBC version 2 % optimization interfaces. % Copyright 2006-2008 The MathWorks, Inc. freevals = cell(1, length(obj.FreeVariableIndices)); stats = []; OK = zeros(1, length(obj.RunIndices)); msg = cell(1, length(obj.RunIndices)); mainOK = true; mainmsg = ''; % Turn waitbar off for the v2 interface if DOWAITBAR waitH.waitbar.visible = 'off'; end obj = nextRun(obj); cos = cgoptimstore(obj); try % Evaluate function cos = feval(obj.FunctionName, 'evaluate', cos); % Retrieve results [OK, msg, stats] = getOutputInfo(cos); freevalmatrix = getFreeVariables(cos); catch ME mainOK = false; mainmsg = sprintf('%s\n\n%s', ... 'An error occurred while running the optimization function:', ... ME.message); end if mainOK % Split free variable data into the values for each variable VarLen = obj.InputDataLengths(obj.FreeVariableIndices); k = 1; for n = 1:length(freevals) freevals{n} = permute(freevalmatrix(:, k:k+VarLen(n)-1, :), [3 2 1]); k = k+VarLen(n); end end