Average, minimum or maximum of surfaces. Usage: surf = SurfStatAvSurf( filenames [, fun] ); filenames = n x k cell array of names of files. fun = function handle to apply to two surfaces, e.g. = @plus (default) will give the average of the surfaces, = @min or @max will give the min or max, respectively. surf.coord = 3 x v matrix of average coordinates, v=#vertices. surf.tri = t x 3 matrix of triangle indices, 1-based, t=#triangles. The coordinates and triangle indices of the k files are concatenated.
0001 function surf = SurfStatAvSurf( filenames, fun ); 0002 0003 %Average, minimum or maximum of surfaces. 0004 % 0005 % Usage: surf = SurfStatAvSurf( filenames [, fun] ); 0006 % 0007 % filenames = n x k cell array of names of files. 0008 % fun = function handle to apply to two surfaces, e.g. 0009 % = @plus (default) will give the average of the surfaces, 0010 % = @min or @max will give the min or max, respectively. 0011 % 0012 % surf.coord = 3 x v matrix of average coordinates, v=#vertices. 0013 % surf.tri = t x 3 matrix of triangle indices, 1-based, t=#triangles. 0014 % The coordinates and triangle indices of the k files are concatenated. 0015 0016 if nargin<2 0017 fun=@plus; 0018 end 0019 0020 [n,k]=size(filenames); 0021 fprintf(1,'%s',[num2str(n) ' x ' num2str(k) ' files to read, % remaining: 100 ']); 0022 n10=floor(n/10); 0023 ab='a'; 0024 for i=1:n 0025 if rem(i,n10)==0 0026 fprintf(1,'%s',[num2str(round(100*(1-i/n))) ' ']); 0027 end 0028 if i==1 0029 [s,ab]=SurfStatReadSurf(filenames(i,:),ab,2); 0030 surf.tri=s.tri; 0031 surf.coord=double(s.coord); 0032 m=1; 0033 % passing ab speeds up reading if the next file has the same format. 0034 else 0035 [s,ab]=SurfStatReadSurf(filenames(i,:),ab,1); 0036 surf.coord=fun(surf.coord,double(s.coord)); 0037 m=fun(m,1); 0038 end 0039 end 0040 surf.coord=surf.coord/m; 0041 fprintf(1,'%s\n','Done'); 0042 0043 return 0044 end