如何使用fieldtrip工具箱在spisific时间从缓冲区读取最后一个valuse

时间:2015-05-28 09:44:19

标签: matlab

我想在特定时间从fieldtrip工具箱缓冲区读取,我执行一个导致脑刺激的实验,所以我想阅读eeg数据反应的 实验

我能够读取连续数据,这是我的代码:

run=1;
filename = 'buffer://localhost:1972';       %set buffer
% read the header for the first time to determine number of channels and sampling rate
hdr = ft_read_header(filename, 'cache', true);  %header of buffer
count      = 0;
prevSample = 0;
blocksize  = hdr.Fs;        %size if readig on blick
chanindx   = 1:hdr.nChans;
while true
  hdr = ft_read_header(filename, 'cache', true);
  newsamples = (hdr.nSamples*hdr.nTrials-prevSample);
  if newsamples>=blocksize
    begsample  = prevSample+1;
    endsample  = prevSample+blocksize ;
    prevSample  = endsample;
    count       = count + 1;
    dat = ft_read_data(filename, 'header', hdr, 'begsample', begsample, 'endsample', endsample, 'chanindx', chanindx);
    time = (begsample:endsample)/hdr.Fs;
    vals= (dat([15 1 2 3],1:end)).';%get rows 1,2,3 and 15=timestamp, transpose it
    plot(time,vals);
    run=run+1;
    if(run==100)
        break;
    end
  end % if new samples available
end % while true

0 个答案:

没有答案