ParseFSSegments.m: Difference between revisions
(Created page with "<nowiki> 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...") |
No edit summary |
||
Line 1: | Line 1: | ||
< | <code> | ||
function segdetails = parseFSSegments(fname) | function segdetails = parseFSSegments(fname) | ||
%%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 | ||
Line 69: | Line 69: | ||
segdetails.segrange=segrange; | segdetails.segrange=segrange; | ||
end | end | ||
</ | </code> |
Revision as of 14:00, 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