0001 function coherence_array = get_eeg_coherence(fid,freqs,obs,nfiles,NChan,NFreq,Epoch)
0002
0003
0004 if fid < 0
0005 error('what the hell are you doing')
0006 end;
0007 obs_mask = zeros(1,nfiles);
0008 obs_mask(obs) = ones(1,size(obs,2));
0009 icount = 1;
0010 for i = 1:nfiles
0011 if obs_mask(i) > 0
0012 avgcoherence = fread(fid,[NChan(i),NFreq(i)],'float');
0013 avgcoherence = avgcoherence';
0014 freq = freqs*Epoch(i) + ones(1,size(freqs,2));
0015 coherence_array(icount:icount+size(freqs,2)-1,:) = avgcoherence(freq,:);
0016 icount = icount+size(freqs,2);
0017 else
0018 skip_bytes = NChan(i)*NFreq(i)*4;
0019 fseek(fid,skip_bytes,'cof');
0020 end
0021 end;
0022 if (icount-1 ~= size(freqs,2)*size(obs,2))
0023 error('coherence read had a problem')
0024 end;
0025 frewind(fid);