www.gusucode.com > mbc 工具箱 matlab 源码程序 > mbc/@mbcfoundation/@functionlookup/loadMappingFile.m

    function obj = loadMappingFile(obj, filename)
%LOADMAPPINGFILE Initialise the function lookup from a text file.
%
%   LK = LOADMAPPINGFILE( LK, MAPFILE )
%

%   Copyright 2005-2011 The MathWorks, Inc.

% Get the information out of the ClassMapping  file
data = readtext(filename);

% Make sure there are an even number of elements in the mapping file
if mod(length(data), 2) ~= 0
    error(message('mbc:functionlookup:InvalidMappingFile'));
end
keys = data(1:2:end);
values = data(2:2:end);
obj.Keys = keys;
for n = 1:length( values )
    obj.Values{n} = str2func( values{n} );
end

% Update the actual construction mechanism
obj.KeyCache = {};
obj.ValueIndex = [];
obj.pAppendEncounteredKeys(keys, 1:length(keys));

% read the mappings in the file
function data = readtext(filename)
fid = fopen(filename);
closeFile = onCleanup(@()fclose(fid));
data = textscan(fid, '%s');
data = data{1};