www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptimtablefiller/private/pGetTableData.m
function [filldata,msg] = pGetTableData(otf, seldata, coninds, ptrlist, table_no) %PGETTABLEDATA Get the data to fill a particular table % % FILLDATA = PGETTABLEDATA(OTF, SELDATA, CONINDS, PTRLIST, TABLE_NO) gets % the fill data to fill the TABLE_NO-th table in OTF. The data, SELDATA, % is retrieved from selected solution in the optimization results. The % pointers to the columns in the optimization output cube are passed % through PTRLIST. If the user has selected to filter infeasible results, % the logical matrix CONINDS is used. % Copyright 2000-2013 The MathWorks, Inc. and Ford Global Technologies, Inc. % Initialise filldata = []; % Get the table to be filled LT = info(otf.tables(table_no)); Ninputs = size(seldata, 2); [axesind,seldata,msg] = getAxesData(otf,LT,seldata,ptrlist); if ~isempty(msg) return end % calculate filters from filter rules [reqinds,msg] = evaluateFilterRules(otf,table_no,seldata,ptrlist,coninds); if ~isempty(msg) return end % now get output data for table [filldata,msg] = getOutputData(otf,table_no,seldata(reqinds,:),ptrlist,axesind,Ninputs); if ~isempty(msg) return end if otf.includelocks % augment filldata with locked table values. This forces the % table filling routine to interpolate the locked values. Locked cell % values override optimization results. filldata = addTableData(filldata,LT,logical(get(LT,'vlocks')),false); end if otf.includemask % augment filldata with mask table values. This forces the % table filling routine to interpolate the existing mask values. If the % cell is specified in the optimization results then the optimization % result is used. filldata = addTableData(filldata,LT,getExtrapolationMask(LT),true); end function filldata = addTableData(filldata,LT,Map,cleartofill) if any(Map(:)) V = get(LT,'values'); %this only works for simple tables (with variable inputs) bps=get(LT,'axes'); if length(bps)>1 % 2D table [bps{:}]=meshgrid(bps{:}); TableData = [bps{1}(Map) bps{2}(Map) V(Map)]; else % 1D table TableData = [bps{1}(Map) V(Map)]; end [InBoth,ia,ib]= intersect(TableData(:,1:end-1),filldata(:,1:end-1),'rows'); if ~isempty(InBoth) if cleartofill % remove from table so filling can update this % value TableData(ia,:) = []; else % remove map points from fill data so table data is used filldata(ib,:) = []; end end filldata = [filldata; TableData]; end function [y,msg] = evaluateExpression(E,ptrlist,seldata) %evaluateExpression evaluate an expression to use for filling table [~,inpinds]= ismember(getinports(E),ptrlist); msg = ''; indata = num2cell(seldata(:, inpinds), 1); try y = cgsimfill.ExpressionChain.fastEvaluate(E,indata); if ~isequal(size(y,1),size(seldata,1)) || size(y,2)~=1 error(message('mbc:cgoptimtabfiller:InvalidExpressions')) end catch ME y = []; msg = ME.message; end function [axesind,seldata,msg] = getAxesData(otf,LT,seldata,ptrlist) %getAxesData get data for normalizer inputs Ninputs = size(seldata, 2); msg = ''; % get normalizers for table. Don't use getinputs as the order is wrong! normptrs = get(LT,'normalizers'); % Get indices of axes inputs in pointer list of optimization output factors axesptrs = get(LT,'axesptrs'); axesind= zeros(1, length(axesptrs)); for i = 1:length(axesptrs) index = normptrs(i)==otf.normalizerlinks(:,1); if ~isempty(index) % need to evaluate an expression % evaluate link expression if find(otf.normalizerlinks(index,2)==ptrlist)<=Ninputs % axes input is a variable so copy from data axesind(i) = find(otf.normalizerlinks(index,2)==ptrlist); else % axes input is an expression E = otf.normalizerlinks(index,2).info; [axeslink,msg] = evaluateExpression(E,ptrlist,seldata); if ~isempty(msg) return end % link expression will be added to the end of seldata axesind(i) = size(seldata,2)+1; seldata = [seldata axeslink]; end elseif any(ptrlist==axesptrs(i)) % data in optimization results - legacy case axesind(i) = find(ptrlist==axesptrs(i)); else error(message('mbc:cgoptimtabfiller:InvalidTableInput')) end end function [reqinds,msg] = evaluateFilterRules(otf,table_no,seldata,ptrlist,coninds) %evaluateFilterRules evaluate filter rules msg= ''; if ~getUseAcceptableOnly(otf) reqinds = true(1, size(seldata, 1)); else reqinds = coninds; end reqinds= reqinds(:); % use rule to filter points if ~isempty(otf.filterfcns) && ~isempty(otf.filterfcns{table_no}) E = otf.filterfcns{table_no}; [keep,msg] = evaluateExpression(E,ptrlist,seldata); if isempty(msg) && all(ismember(keep,[0 1])) reqinds = reqinds & keep; end end function [filldata,msg] = getOutputData(otf,table_no,seldata,ptrlist,axesind,Ninputs) %getOutputData get data for filling table values % Get index of selected output column outptr = otf.fillfactors(table_no); outind = find(ptrlist==outptr); filldata = []; % Check for zeros in axes/out indices indcheck = [axesind, outind]; if any(~indcheck) % An axis pointer or the selected output is no longer in the data set msg = 'The axes or output data is not in optimization results.'; return end msg = ''; if outind > Ninputs % Filling from an expression (currently a model or formula) if ~isempty(seldata) E = ptrlist(outind).info; [outdata,msg] = evaluateExpression(E,ptrlist,seldata); if ~isempty(msg) return end else outdata = zeros(0,1); end % Create output filldata = [seldata(:, axesind), outdata]; else % Filling from an optimization fixed/free variable filldata = seldata(:, [axesind outind]); end