ParseFSSegments.m: Difference between revisions

From CCN Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:
%%Given a filename fname, pull out the names of each segment. fname is the
%%Given a filename fname, pull out the names of each segment. fname is the
%%name of a file produced by mri_segstats
%%name of a file produced by mri_segstats
if (~exist('fname'))
if (~exist('fname'))
     fname=uigetfile('*.sum.txt');
     fname=uigetfile('*.sum.txt');
end
end
 
 
%open the file
%open the file
fid=fopen(fname, 'r');
fid=fopen(fname, 'r');
Line 14: Line 12:
     error(['Specified segment file ''' fname ''' not found']);
     error(['Specified segment file ''' fname ''' not found']);
end
end
 
%First, count number of entries
%First, count number of entries
%read in file, line by line, until we reach end of file
%read in file, line by line, until we reach end of file
Line 57: Line 55:
     end
     end
end
end
 
segdetails.colidx=colidx;
segdetails.colidx=colidx;
segdetails.segid=segid;
segdetails.segid=segid;

Revision as of 14:01, 7 June 2016

function segdetails = parseFSSegments(fname) %%Given a filename fname, pull out the names of each segment. fname is the %%name of a file produced by mri_segstats if (~exist('fname'))

   fname=uigetfile('*.sum.txt');

end

%open the file fid=fopen(fname, 'r'); if(fid<=0)

   error(['Specified segment file  fname  not found']);

end

%First, count number of entries %read in file, line by line, until we reach end of file linecount=0; while ~feof(fid)

   line=fgets(fid);
   if(line(1)~='#')
       %only interested in lines not starting with hash
       linecount=linecount+1;
   end

end %rewind to beginning of file now that we know how many lines of interest frewind(fid) %preallocate variables segname=cell(linecount,1); colidx=nan(linecount,1); segid=nan(linecount,1); nvertices=nan(linecount,1); segarea=nan(linecount,1); segmean=nan(linecount,1); segstd=nan(linecount,1); segmin=nan(linecount,1); segmax=nan(linecount,1); segrange=nan(linecount,1); linecount=0; %recycle linecount variable to track where to store interesting lines while ~feof(fid)

   line=fgets(fid);
   if(line(1)~='#')
       %STILL only interested in lines not starting with hash!
       linecount=linecount+1;
       A=sscanf(line, '%d %d %d %f %s %f %f %f %f %f');
       colidx(linecount)=A(1);
       segid(linecount)=A(2);
       nvertices(linecount)=A(3);
       segarea(linecount)=A(4);
       segname{linecount}=char(A(5:length(A)-5))';
       segmean(linecount)=A(length(A)-4);
       segstd(linecount)=A(length(A)-3);
       segmin(linecount)=A(length(A)-2);
       segmax(linecount)=A(length(A)-1);
       segrange(linecount)=A(length(A));
   end

end

segdetails.colidx=colidx; segdetails.segid=segid; segdetails.nvertices=nvertices; segdetails.segarea=segarea; segdetails.segname=segname; segdetails.segmean=segmean; segdetails.segstd=segstd; segdetails.segmin=segmin; segdetails.segmax=segmax; segdetails.segrange=segrange; end