Home > vbmeg > external > mne > mne_write_label_file.m

mne_write_label_file

PURPOSE ^

SYNOPSIS ^

function mne_write_label_file(filename,label)

DESCRIPTION ^

 write_read_label_file(filename,label)
 
 Writes label file. The returned structure has the following fields

     filename      output file
     label         a stucture containing the stc data with fields:

     comment        comment for the first line of the label file
     vertices       vertex indices (0 based, column 1)
     pos            locations in meters (columns 2 - 4 divided by 1000)
     values         values at the vertices (column 5)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function mne_write_label_file(filename,label)
0002 %
0003 % write_read_label_file(filename,label)
0004 %
0005 % Writes label file. The returned structure has the following fields
0006 %
0007 %     filename      output file
0008 %     label         a stucture containing the stc data with fields:
0009 %
0010 %     comment        comment for the first line of the label file
0011 %     vertices       vertex indices (0 based, column 1)
0012 %     pos            locations in meters (columns 2 - 4 divided by 1000)
0013 %     values         values at the vertices (column 5)
0014 %
0015 
0016 %
0017 %
0018 %   Author : Matti Hamalainen, MGH Martinos Center
0019 %   License : BSD 3-clause
0020 %
0021 
0022 %
0023 % This is based on the FreeSurfer read_label routine
0024 % SUBJECTS_DIR environment variable is not consulted for the standard location
0025 %
0026 
0027 me='MNE:mne_write_label_file';
0028 if(nargin ~= 2)
0029    error(me,'usage: mne_read_label_file(filename, label)');
0030 end
0031 
0032 if length(label.vertices) ~= length(label.values) || length(label.vertices) ~= size(label.pos,1) || size(label.pos,2) ~= 3
0033    error(me,'fields of the label structure have conflicting or incorrect dimensions');
0034 end
0035 
0036 [fid,message] = fopen(filename,'w');
0037 if (fid < 0)
0038    error(me,'Cannot open file %s (%s)', filename,message);
0039 end;
0040 
0041 if ~isempty(label.comment)
0042    fprintf(fid,'# %s\n',label.comment);
0043 else
0044    fprintf(fid,'# label file written with mne_write_label\n');
0045 end
0046 fprintf(fid,'%d\n',length(label.vertices));
0047 for k = 1:length(label.vertices)
0048    fprintf(fid,'%d %.2f %.2f %.2f %f\n',label.vertices(k),1000*label.pos(k,:),label.values(k));
0049 end
0050 fclose(fid);
0051 
0052

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005