www.gusucode.com > mbcexpr 工具箱 matlab 源码程序 > mbcexpr/@cgslparser/prelookuptable.m
function ptr = prelookuptable(obj,b,blockname,Inputs) %PRELOOKUPTABLE parse a prelookup table % % ptr = prelookuptable(obj,b,blockname,Inputs) % returns a pointer to a lookup table % The prelookup table block must be fed by a prelookup block % Copyright 2007-2012 The MathWorks, Inc. % look at previous blocks to check that they are prelookup SrcBlocks = findSrcBlocks(obj,b); if strcmp( get_param(b,'BlockType'),'Interpolation_n-D' ) NDims = str2double(get(b, 'NumberOfTableDimensions')); % Prelookup tables may use 1 or 2 inputs for each dimension. The % single-input dimensions are "sub-table selection" dimensions. NSingleInputs = str2double(get(b, 'NumSelectionDims')); NDualInputs = NDims - NSingleInputs; % if new prelookup Inputs = [Inputs(1:2:2*NDualInputs) Inputs(2*NDualInputs+1:end)]; % check both index and fraction come from same block OK = all(SrcBlocks(1:2:2*NDualInputs)==SrcBlocks(2:2:2*NDualInputs)); for i=1:length(SrcBlocks) OK = OK && strcmp( get_param(SrcBlocks(i),'BlockType'),'PreLookup' ); end else NDims = get_param(b, 'numDimsPopupSelect'); if strcmp(NDims,'More...') NDims = str2double(get_param(b, 'explicitNumDims')); else NDims = str2double(NDims); end % old prelookup OK = true; for i=1:length(SrcBlocks) OK = OK && strcmp( get_param(SrcBlocks(i),'MaskType'),'LookupIdxSearch' ); end end if ~OK obj.assert('The PreLookup Table block can only be used in conjunction with a PreLookup block',b) end if NDims>2 obj.assert('Lookups can only be 1 or 2D.',b); end ptr = getBlockPointer(obj,b); switch NDims case 1 ptr = lookup1D(obj,b,blockname,ptr,Inputs{1}); case 2 ptr = lookup2D(obj,b,blockname,ptr,[Inputs{:}]'); end