0001 function elec_write_3dspace(p)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
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
0055
0056 fprintf('...converting from meters to cm.\n');
0057
0058
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