0001 function coh = eeg_load_scan_coh_asc(filename)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 [path,name,ext] = fileparts(filename);
0036 file = fullfile(path,[name ext]);
0037
0038 [fid,msg] = fopen(file,'r');
0039 if ~isempty(msg), error(msg); end
0040
0041 tic
0042
0043 fprintf('\nEEG_LOAD_SCAN_COH_ASC...\n');
0044 fprintf('...reading data file:\n\t%s\n',file);
0045
0046 coh = read_coh(fid);
0047
0048 t = toc; fprintf('...done (%6.2f sec).\n\n',t);
0049
0050 return
0051
0052
0053
0054
0055 function [coh] = read_coh(fid)
0056
0057 coh = [];
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 fprintf('...reading header\n');
0073
0074 while 1,
0075 tmp = fgetl(fid);
0076 if strmatch(lower('[Subject]'),lower(tmp)),
0077 coh.subject = strrep(tmp,sprintf('[Subject]\t'),'');
0078 tmp = fgetl(fid);
0079 end
0080 if strmatch(lower('[Date]'),lower(tmp)),
0081 tmp = strrep(tmp,sprintf('[Date]\t'),'');
0082 coh.date = datestr(datenum(tmp));
0083 tmp = fgetl(fid);
0084 end
0085 if strmatch(lower('[Time]'),lower(tmp)),
0086 coh.time = strrep(tmp,sprintf('[Time]\t'),'');
0087 tmp = fgetl(fid);
0088 end
0089 if strmatch(lower('[Channels]'),lower(tmp)),
0090 tmp = strrep(tmp,sprintf('[Channels]\t'),'');
0091 coh.channels = str2num(tmp);
0092 tmp = fgetl(fid);
0093 end
0094 if strmatch(lower('[Rate]'),lower(tmp)),
0095 tmp = strrep(tmp,sprintf('[Rate]\t'),'');
0096 coh.rate = str2num(tmp);
0097 tmp = fgetl(fid);
0098 end
0099 if strmatch(lower('[Type]'),lower(tmp)),
0100 coh.type = strrep(tmp,sprintf('[Type]\t'),'');
0101 tmp = fgetl(fid);
0102 end
0103 if strmatch(lower('[Points]'),lower(tmp)),
0104 tmp = strrep(tmp,sprintf('[Points]\t'),'');
0105 coh.points = str2num(tmp);
0106 tmp = fgetl(fid);
0107 end
0108 if strmatch(lower('[Domain]'),lower(tmp)),
0109 coh.domain = strrep(tmp,sprintf('[Domain]\t'),'');
0110 tmp = fgetl(fid);
0111 end
0112 if strmatch(lower('[Pairs]'),lower(tmp)),
0113 tmp = strrep(tmp,sprintf('[Pairs]\t'),'');
0114 coh.pairs = str2num(tmp);
0115 tmp = fgetl(fid);
0116 end
0117 if findstr(lower(tmp),lower('Data')),
0118 datamatrix = tmp;
0119 tmp = fgetl(fid);
0120 tmp = strrep(tmp,'[' ,'');
0121 tmp = strrep(tmp,']' ,'');
0122 tmp = strrep(tmp,'Hz','');
0123 coh.freqbins = str2num(tmp);
0124 end
0125 break;
0126 end
0127
0128 coh.pairnames = cell(coh.pairs,2);
0129
0130 if findstr(datamatrix,'Pairs by Points'),
0131 coh.data = zeros(coh.pairs,coh.points);
0132 row = coh.pairs;
0133 elseif findstr(datamatrix,'Points by Pairs'),
0134
0135 fprintf('..cannot read data matrix for points by pairs\n');
0136 return
0137
0138
0139 end
0140
0141
0142 fprintf('...reading coherence\n');
0143 for r = 1:row,
0144 tmp = fgetl(fid);
0145 a = findstr(tmp,'[') + 1;
0146 b = findstr(tmp,']') - 1;
0147 c = findstr(tmp,'-');
0148 c = c(1);
0149 coh.pairnames{r,1} = tmp(a:c-1);
0150 coh.pairnames{r,2} = tmp(c+1:b);
0151 coh.data(r,:) = str2num(tmp(b+2:end));
0152 end
0153
0154
0155 tmp = fgetl(fid);
0156 if findstr(tmp,'Phase'),
0157 fprintf('...reading phase (degrees)\n');
0158 tmp = fgetl(fid);
0159 coh.phase = zeros(size(coh.data));
0160 for r = 1:row,
0161 tmp = fgetl(fid);
0162 b = findstr(tmp,']') - 1;
0163 coh.phase(r,:) = str2num(tmp(b+2:end));
0164 end
0165 end
0166
0167 fclose(fid);
0168
0169 return