function S=indexFile2CountMatrix(fname) % function S=indexFile2CountMatrix(fname) % % create a spare term count matrix from an indexed file produced by % indexCorpus.cpp. % % Guy Lebanon, 2005. %figure out the vocab size and the number of distinct files i=0;maxV=0; fid=fopen(fname,'r'); while 1 tline = fgetl(fid); if ~ischar(tline), break, end vec=str2num(tline); if ~isempty(vec), M=max(vec); if M>maxV, maxV=M;end end i=i+1; end fclose(fid); S=sparse(i,maxV+1); fid=fopen(fname,'r'); for i=1:size(S,1), vec=str2num(fgetl(fid)); if isempty(vec), continue;end for j=1:length(vec), S(i,vec(j)+1)=S(i,vec(j)+1)+1; end end fclose(fid);