ParseFSSegments.m: Difference between revisions
Jump to navigation
Jump to search
(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 |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
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 | %%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'); | if(fid<=0) | ||
if(fid<=0) | |||
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 | ||
linecount=0; | linecount=0; | ||
while ~feof(fid) | while ~feof(fid) | ||
line=fgets(fid); | line=fgets(fid); | ||
if(line(1)~='#') | if(line(1)~='#') | ||
Line 24: | Line 21: | ||
linecount=linecount+1; | linecount=linecount+1; | ||
end | end | ||
end | end | ||
%rewind to beginning of file now that we know how many lines of interest | %rewind to beginning of file now that we know how many lines of interest | ||
frewind(fid) | frewind(fid) | ||
%preallocate variables | %preallocate variables | ||
segname=cell(linecount,1); | segname=cell(linecount,1); | ||
colidx=nan(linecount,1); | colidx=nan(linecount,1); | ||
segid=nan(linecount,1); | segid=nan(linecount,1); | ||
nvertices=nan(linecount,1); | nvertices=nan(linecount,1); | ||
segarea=nan(linecount,1); | segarea=nan(linecount,1); | ||
segmean=nan(linecount,1); | segmean=nan(linecount,1); | ||
segstd=nan(linecount,1); | segstd=nan(linecount,1); | ||
segmin=nan(linecount,1); | segmin=nan(linecount,1); | ||
segmax=nan(linecount,1); | segmax=nan(linecount,1); | ||
segrange=nan(linecount,1); | segrange=nan(linecount,1); | ||
linecount=0; %recycle linecount variable to track where to store interesting lines | linecount=0; %recycle linecount variable to track where to store interesting lines | ||
while ~feof(fid) | while ~feof(fid) | ||
line=fgets(fid); | line=fgets(fid); | ||
if(line(1)~='#') | if(line(1)~='#') | ||
Line 56: | Line 53: | ||
segrange(linecount)=A(length(A)); | segrange(linecount)=A(length(A)); | ||
end | end | ||
end | end | ||
segdetails.colidx=colidx; | segdetails.colidx=colidx; | ||
segdetails.segid=segid; | segdetails.segid=segid; | ||
segdetails.nvertices=nvertices; | segdetails.nvertices=nvertices; | ||
segdetails.segarea=segarea; | segdetails.segarea=segarea; | ||
segdetails.segname=segname; | segdetails.segname=segname; | ||
segdetails.segmean=segmean; | segdetails.segmean=segmean; | ||
segdetails.segstd=segstd; | segdetails.segstd=segstd; | ||
segdetails.segmin=segmin; | segdetails.segmin=segmin; | ||
segdetails.segmax=segmax; | segdetails.segmax=segmax; | ||
segdetails.segrange=segrange; | segdetails.segrange=segrange; | ||
end | end | ||
Latest revision as of 14:04, 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