Home > bioelectromagnetism > elec_write_3dspace.m

elec_write_3dspace

PURPOSE ^

elec_write_3dspace - Write electrode coordinate file (ascii).

SYNOPSIS ^

function elec_write_3dspace(p)

DESCRIPTION ^

 elec_write_3dspace - Write electrode coordinate file (ascii).
 
 Useage: elec_write_3dspace(p)
 
 Write out the electrode labels, type, and Cartesian (x,y,z)
 coordinates in the format of Neuroscan 3Dspace ascii files.
 
 Each row of the file comprises an electrode label, an 
 electrode type code (see below), and the x,y,z 
 coordinates (cm). Each field is separated by spaces.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function elec_write_3dspace(p)
0002 
0003 % elec_write_3dspace - Write electrode coordinate file (ascii).
0004 %
0005 % Useage: elec_write_3dspace(p)
0006 %
0007 % Write out the electrode labels, type, and Cartesian (x,y,z)
0008 % coordinates in the format of Neuroscan 3Dspace ascii files.
0009 %
0010 % Each row of the file comprises an electrode label, an
0011 % electrode type code (see below), and the x,y,z
0012 % coordinates (cm). Each field is separated by spaces.
0013 %
0014 
0015 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:34 $
0016 
0017 % Licence:  GNU GPL, no express or implied warranties
0018 % History:  10/2002, Darren.Weber_at_radiology.ucsf.edu
0019 %
0020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0021 
0022 fprintf('\nELEC_WRITE_3DSPACE...\n'); tic;
0023 
0024 if ~exist('p', 'var'),
0025     msg = sprintf('...no input p struct.\n\n');
0026     error(msg);
0027 end
0028 
0029 [path,name,ext] = fileparts(strcat(p.elec.path,filesep,p.elec.file));
0030 ext = '.dat';
0031 file = fullfile(path,[name ext]);
0032 
0033 fprintf('...writing electrode data to:\n\t%s\n', file);
0034 
0035 write_elec(file,p.elec.data);
0036 
0037 t=toc; fprintf('...done (%5.2f sec).\n\n',t);
0038 
0039 return
0040 
0041 
0042 
0043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0045 function write_elec(file,elec);
0046 
0047 fid = fopen(file,'w','ieee-le');
0048 
0049 if(fid == -1),
0050     fprintf('...could not open file:\n\t%s',file);
0051     return;
0052 else
0053     
0054     % Write out the electrode coordinates
0055     
0056     fprintf('...converting from meters to cm.\n');
0057     % Convert to Neuroscan 3Dspace coordinate
0058     % metric (cm) from meters.
0059     
0060     nasion = elec.nasion .* 100;
0061     rpa    = elec.rpa .* 100;
0062     lpa    = elec.lpa .* 100;
0063     
0064     x = elec.x .* 100;
0065     y = elec.y .* 100;
0066     z = elec.z .* 100;
0067     
0068     ref = elec.ref .* 100;
0069     
0070     centroid = elec.centroid .* 100;
0071     
0072     
0073     fprintf('...writing output coordinates.\n');
0074     
0075     fprintf(fid,'%+10s\t%3d\t%+12.6f\t%+12.6f\t%+12.6f\n','Nasion',  110, nasion);
0076     fprintf(fid,'%+10s\t%3d\t%+12.6f\t%+12.6f\t%+12.6f\n','Left',    108, lpa);
0077     fprintf(fid,'%+10s\t%3d\t%+12.6f\t%+12.6f\t%+12.6f\n','Right',   114, rpa);
0078     
0079     Nelec = size(x,1);
0080     type = 69;
0081     for e = 1:Nelec,
0082         fprintf(fid,'%+10s\t%3d\t%+12.6f\t%+12.6f\t%+12.6f\n',char(elec.label(e)), type, x(e), y(e), z(e));
0083     end
0084     
0085     fprintf(fid,'%+10s\t%3d\t%+12.6f\t%+12.6f\t%+12.6f\n','Centroid', 99, centroid(1),centroid(2),centroid(3));
0086     fprintf(fid,'%+10s\t%3d\t%+12.6f\t%+12.6f\t%+12.6f\n','Ref',     120, ref(1),ref(2),ref(3));
0087     
0088     fclose(fid);
0089     
0090 end
0091 
0092 return
0093

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