countConS.m 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. function [avLCl] = countConS(dataIn,seq,nTrials)
  2. % IDENTIFY consecutive standard responses
  3. % This function identifies consecutive standard responses in the oddball
  4. % paradigm. The number of responses is defined by nConS
  5. % define some variables
  6. nBlcks = size(dataIn,3);
  7. nFiles = size(dataIn,4);
  8. avLCl = zeros(nBlcks,nFiles);
  9. for f = 1:nFiles
  10. for b = 1:nBlcks
  11. % create std sequences
  12. seqStd = ~seq(1:nTrials(b,f),b,f)';
  13. vecClI = double(seqStd);
  14. % count appearances of consecutive standards in each cluster (code from forum)
  15. B = vecClI;
  16. d2 = [true,diff(B)~=0];
  17. r = find(d2);
  18. B(~d2) = 1;
  19. B(d2) = [1,1-diff(r)];
  20. B(1) = 1;
  21. B = cumsum(B);
  22. % identify number and size of accepted clusters
  23. bCl = diff([0,vecClI,0]); % vector that marks borders of clusters
  24. sCl = find(bCl==1); % starting points of clusters
  25. eCl = find(bCl==-1)-1; % ending points of clusters
  26. lCl = eCl-sCl+1; % size of clusters
  27. % calculate average length of clusters
  28. avLCl(b,f) = mean(lCl);
  29. end
  30. end