Home > bioelectromagnetism > freesurfer_read_wfile.m

freesurfer_read_wfile

PURPOSE ^

freesurfer_read_wfile - FreeSurfer I/O function to read an overlay (*.w) file

SYNOPSIS ^

function [w,v] = freesurfer_read_wfile(fname)

DESCRIPTION ^

 freesurfer_read_wfile - FreeSurfer I/O function to read an overlay (*.w) file
 
 [w,vert] = freesurfer_read_wfile(fname)
 
 reads a vector from a binary 'w' file
    fname - name of file to read from
    w     - vector of values
   vert  - vertex indices
 
 After reading an associated surface, with freesurfer_read_surf, try:
 patch('vertices',vert,'faces',face,...
       'facecolor','interp','edgecolor','none',...
       'FaceVertexCData',w); light
 
 See also freesurfer_write_wfile, freesurfer_read_surf, freesurfer_read_curv

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [w,v] = freesurfer_read_wfile(fname)
0002 
0003 % freesurfer_read_wfile - FreeSurfer I/O function to read an overlay (*.w) file
0004 %
0005 % [w,vert] = freesurfer_read_wfile(fname)
0006 %
0007 % reads a vector from a binary 'w' file
0008 %    fname - name of file to read from
0009 %    w     - vector of values
0010 %   vert  - vertex indices
0011 %
0012 % After reading an associated surface, with freesurfer_read_surf, try:
0013 % patch('vertices',vert,'faces',face,...
0014 %       'facecolor','interp','edgecolor','none',...
0015 %       'FaceVertexCData',w); light
0016 %
0017 % See also freesurfer_write_wfile, freesurfer_read_surf, freesurfer_read_curv
0018 
0019 if (nargin ~= 1),
0020     msg = sprintf('USAGE: [w,v] = freesurfer_read_wfile(fname)\n');
0021     error(msg);
0022 end
0023 
0024 % open it as a big-endian file
0025 fid = fopen(fname, 'rb', 'b') ;
0026 if (fid < 0),
0027     str = sprintf('could not open w file %s.', fname) ;
0028     error(str) ;
0029 end
0030 
0031 fread(fid, 1, 'int16');  % Skip latency int
0032 
0033 vnum = freesurfer_fread3(fid) ;  % Number of non-zero values
0034 v = zeros(vnum,1) ;
0035 w = zeros(vnum,1) ;
0036 for i=1:vnum,
0037     v(i) = freesurfer_fread3(fid) ;
0038     w(i) = fread(fid, 1, 'float') ;
0039 end
0040 
0041 fclose(fid) ;
0042 
0043 if nargout > 1,
0044     fprintf('...adding 1 to vertex indices for matlab compatibility.\n');
0045     v = v + 1;
0046 end
0047 
0048 % w = zeros(max(v),1);
0049 % w(v+1) = w0;
0050 
0051 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003