Home > fmri > fsl > get_middle_vol.m

get_middle_vol

PURPOSE ^

volidx = get_middle_vol(fname, logfid);

SYNOPSIS ^

function volidx = get_middle_vol(fname, logfid)

DESCRIPTION ^

 volidx = get_middle_vol(fname, logfid);

 Returns the index of the middle volume in a 4D data volume

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function volidx = get_middle_vol(fname, logfid)
0002 % volidx = get_middle_vol(fname, logfid);
0003 %
0004 % Returns the index of the middle volume in a 4D data volume
0005 %
0006 
0007 % 10/26/05 Petr Janata
0008 
0009 % check existence of file
0010 if ~exist(fname,'file') && ~exist([fname '.nii'],'file') ...
0011         && ~exist([fname '.nii.gz'],'file')
0012   error('get_middle_vol:Could not find file: %s', fname)
0013 end
0014 
0015 try logfid;
0016 catch logfid = 1;
0017 end
0018 
0019 fsl_str = sprintf('fslnvols %s', fname);
0020 fprintf(logfid,'%s\n', fsl_str);
0021 [status, volidx] = unix(fsl_str);  % get the number of volumes
0022 volidx = str2num(volidx);
0023 volidx = fix(volidx/2);  % take middle timepoint
0024 
0025 if volidx == 0
0026   volidx = 1;
0027 end

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003