Converts a vertex index to x,y,z coordinates. Usage: coord = SurfStatInd2Coord( ind, surf ); ind = 1 x c vector of indices of vertex, 1-based. surf.coord = 3 x v matrix of coordinates. or surf.lat = 3D logical array, 1=in, 0=out. surf.vox = 1 x 3 vector of voxel sizes in mm, [1 1 1] by default. surf.origin = position in mm of the first voxel, [0 0 0] by default. coord = 3 x c matrix of coordinates.
0001 function coord = SurfStatInd2Coord( ind, surf ); 0002 0003 %Converts a vertex index to x,y,z coordinates. 0004 % 0005 % Usage: coord = SurfStatInd2Coord( ind, surf ); 0006 % 0007 % ind = 1 x c vector of indices of vertex, 1-based. 0008 % surf.coord = 3 x v matrix of coordinates. 0009 % or 0010 % surf.lat = 3D logical array, 1=in, 0=out. 0011 % surf.vox = 1 x 3 vector of voxel sizes in mm, [1 1 1] by default. 0012 % surf.origin = position in mm of the first voxel, [0 0 0] by default. 0013 % 0014 % coord = 3 x c matrix of coordinates. 0015 0016 if isfield(surf,'coord') 0017 coord=surf.coord(:,ind); 0018 end 0019 if isfield(surf,'lat') 0020 if ~isfield(surf,'vox') 0021 surf.vox=ones(1,3); 0022 end 0023 if ~isfield(surf,'origin'); 0024 surf.origin=zeros(1,3); 0025 end 0026 vid=cumsum(surf.lat(:)).*surf.lat(:); 0027 [tf,loc]=ismember(ind,vid); 0028 loc(loc==0)=NaN; 0029 dim=size(surf.lat); 0030 [i,j,k]=ind2sub(dim,loc); 0031 coord=zeros(3,length(ind)); 0032 coord(1,:)=surf.origin(1)+(i-1)*surf.vox(1); 0033 coord(2,:)=surf.origin(2)+(j-1)*surf.vox(2); 0034 coord(3,:)=surf.origin(3)+(k-1)*surf.vox(3); 0035 end 0036 0037 return 0038 end 0039