www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgoptimnode/attachNewOutput.m
function [obj, pOutNode] = attachNewOutput(obj, Output) %ATTACHNEWOUTPUT Attach a new output data object to the optimization. % % [OBJ, POUTNODE] = ATTACHNEWOUTPUT(OBJ,OUT) adds the new optimization % output OUT to the optimization. This will either add a new output node % child or reuse an existing one if appropriate. The output node that % has been used is returned in POUTNODE. % Copyright 2006 The MathWorks, Inc. pAllOutNodes = children(obj); if isempty(pAllOutNodes) % Make a new node obj = addOutput(obj, xregpointer(Output)); pOutNode = children(obj); else % Find the last un-held existing output IsHeld = parrayeval(pAllOutNodes, @isPreserved, [], mbclogical); UseIdx = find(~IsHeld, 1, 'last'); if isempty(UseIdx) % Assume that the last output is the latest. Get the table filler % from this output node. nOut = length(IsHeld); pLastOut = getOutput(obj, nOut); OldTableFiller = getTableFiller(pLastOut.info); % Make a new node obj = addOutput(obj, xregpointer(Output)); pOutNode = children(obj); pOutNode = pOutNode(end); else % Use existing node. pCurrentOut = getOutput(obj, UseIdx); % Get the existing table filler object OldTableFiller = getTableFiller(pCurrentOut.info); % The data is put into the existing data pointer within the output % node. Output = setname(Output, pCurrentOut.getname); setaddress(Output, pCurrentOut); pOutNode = pAllOutNodes(UseIdx); end % Put the table filler in the new output object pNewOut = pOutNode.getdata; pNewOut.info = setTableFiller(pNewOut.info, OldTableFiller); end