www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptim/private/pGetValueSizes.m

    function Lengths = pGetValueSizes(optim, pVal)
%PGETVALUESIZES Return the length of the data in specified values
%
%  LENGTHS = PGETVALUESIZES(OPTIM, PVAL) returns the length of the stored
%  setup data in each variable in PVAL.

%  Copyright 2005 The MathWorks, Inc. and Ford Global Technologies, Inc.


% Make the list of items unique and get the zero-th stored data item for
% this optimization.  This location contains the current data size for each
% variable.
pIndepVal = cgindependentvars(pVal);
Lengths = parrayeval(pIndepVal, @i_getstoredlen, {optim.SetupGUID}, mbcdouble);

% If some variables depended on others then we need to work out the lengths
% for other variables.  The easiest way to do this is by setting test
% vectors in the variables and measuring the lengths 
if length(pIndepVal)~=length(pVal)
    passign(pIndepVal, parrayeval(pIndepVal, @i_settestvector, {Lengths}));
    Lengths = parrayeval(pVal, @i_getvaluelen, {}, mbcdouble);
end



function L = i_getstoredlen(val, guid)
L = getstorevalue(val, guid, 0);
if isempty(L)
    L = 1;
end

function val = i_settestvector(val, len)
val = setvalue(val, repmat(getnomvalue(val), len,1));

function L = i_getvaluelen(val)
L = length(getvalue(val));