translateList Translate a list of identifiers (either numerical or cell array) using a dictionary list = translateList(list,trList1,trList2) Usage: Define original list list = {'a','b','c'} Define dictionary trList1 = {'b','c'} trList2 = {'B','C'} newList = translateList(list,trList1,trList2); returns newList = {'a','B','C'}; Markus Herrgard 8/17/06
0001 function list = translateList(list,trList1,trList2) 0002 %translateList Translate a list of identifiers (either numerical or cell 0003 %array) using a dictionary 0004 % 0005 % list = translateList(list,trList1,trList2) 0006 % 0007 % Usage: 0008 % 0009 % Define original list 0010 % 0011 % list = {'a','b','c'} 0012 % 0013 % Define dictionary 0014 % 0015 % trList1 = {'b','c'} 0016 % trList2 = {'B','C'} 0017 % 0018 % newList = translateList(list,trList1,trList2); 0019 % 0020 % returns 0021 % 0022 % newList = {'a','B','C'}; 0023 % 0024 % Markus Herrgard 8/17/06 0025 0026 [isInList,listInd] = ismember(list,trList1); 0027 0028 list(isInList) = trList2(listInd(listInd ~= 0));