fid = fopen('/Users/tlberg/Desktop/teaching/Spring_09/demos/text.txt','r'); count=0; while 1 tline = fgetl(fid); if ~ischar(tline), break, end r = tline; while ~isempty(r) [t,r] = strtok(r); if strcmp(t,'text') count=count+1; end end end fclose(fid); fid = fopen('/Users/tlberg/Desktop/teaching/Spring_09/demos/text.txt','r'); count=0; while 1 tline = fgetl(fid); if ~ischar(tline), break, end a = strfind(tline,'text'); if ~isempty(a) count=count+length(a); end end fclose(fid);