function Im=sumImages(fileIndex,theDir); %function Im=sumImages(fileIndex,theDir); %adds tif files in fileIndex, under theDir, if no directory assumes current %doesn't use filenumbers, just the order in which they appear in the %directory %minus sign subtracts if nargin == 1 theDir = '.' end ImFiles =dir(strcat(theDir,'/*.tif')); Im = zeros(195,487); for j=fileIndex if (j<0) j=-j; %subtract file s=-1; else s=1; %add file end fprintf('adding file %s\n',ImFiles(j).name); Im=Im+s*imageread(strcat(theDir,'/',ImFiles(j).name),'tif',[487,195],32); end