function v = index2label (ca, indexfile) % INDEX2LABEL converts a cell array to a vector of indices using an index file % % ca is a Mx1 cell array % indexfile has is a file with M nonempty lines that dont start with a % % Each such line is of the form % lab ind % where lab is some string/number without spaces and ind is a number. % No lab appears twice. % % v is a Mx1 vector with v(i) having an integer corresponding to ca{i} % ca{i} and v(i) are on the same line of indexfile. indices = textread (indexfile, '%s', 'commentstyle', 'matlab', 'headerlines',0, 'delimiter', '\n' ); ind_lab = {}; ind_num = []; for i = 1 : length (indices) a = strread (indices{i},'%s','delimiter',' '); ind_lab{i} = a{1}; ind_num(i) = str2num(a{2}); end L = length(ca); v = zeros(L,1); for i = 1 : L f = findincell (ind_lab, ca{i}); if f > 0 v(i) = ind_num(f); end end