


BML_MAP maps elements based on given domain and codomain Use as mapped = bml_map(element,domain,codomain) element - cellstr, cell or array domain - cellstr, cell or array. Possible elements to match with codomain - cellstr, cell or array. Corresponding elements returns the corresponding codomain element for each given domain element


0001 function mapped = bml_map(element,domain,codomain) 0002 0003 % BML_MAP maps elements based on given domain and codomain 0004 % 0005 % Use as 0006 % mapped = bml_map(element,domain,codomain) 0007 % 0008 % element - cellstr, cell or array 0009 % domain - cellstr, cell or array. Possible elements to match with 0010 % codomain - cellstr, cell or array. Corresponding elements 0011 % 0012 % returns the corresponding codomain element for each given domain element 0013 0014 if ischar(element) 0015 element = {element}; 0016 end 0017 0018 if iscellstr(element) 0019 assert(iscellstr(domain),'incompatible elements and domain'); 0020 %assert(iscellstr(codomain),'incompatible elements and codomain'); 0021 mapped = cellfun(@(x) codomain(find(strcmp(domain,x),1)),element,'UniformOutput',true); 0022 elseif iscell(element) 0023 assert(iscell(domain),'incompatible elements and domain'); 0024 %assert(iscell(codomain),'incompatible elements and codomain'); 0025 mapped = cellfun(@(x) codomain(find(domain==x,1)),element,'UniformOutput',true); 0026 elseif isnumeric(element) 0027 assert(isnumeric(domain),'incompatible elements and domain'); 0028 %assert(isnumeric(codomain),'incompatible elements and codomain'); 0029 mapped = arrayfun(@(x) codomain(find(domain==x,1)),element); 0030 else 0031 error('unknown type for element'); 0032 end