Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

countconsecutiveones.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. function [c1cv, isq1s, isq1e, xv_min_seq_length] =countconsecutiveones(xv,zero_pad,min_seq_length)
  2. if nargin <2
  3. zero_pad=0;
  4. if nargin <3
  5. min_seq_length=1;
  6. end
  7. end
  8. isq1s=nan(size(xv));
  9. isq1e=nan(size(xv));
  10. c1cv=nan(size(xv));
  11. xv_min_seq_length=zeros(size(xv));
  12. if isvector(xv)
  13. if isrow(xv)
  14. xv=xv';
  15. end
  16. if zero_pad
  17. xv(isnan(xv))=0;
  18. else
  19. xv(isnan(xv))=[];
  20. end
  21. %fv = find(abs(diff([0; xv; 0]==1)))
  22. %c1cv = fv(2:2:end)-fv(1:2:end-1);
  23. xdiff=diff([0; xv; 0]);
  24. i1sct = find(xdiff==+1); %indices where ones sequence start
  25. i1ect = find(xdiff==-1); %indices where ones sequence end
  26. c1ct = i1ect - i1sct;
  27. isq1s(1:length(i1sct))=i1sct;
  28. isq1e(1:length(i1ect))=i1ect;
  29. c1cv(1:length(c1ct))=c1ct;
  30. isq1se=[isq1s(c1cv>min_seq_length) isq1e(c1cv>min_seq_length)];
  31. if ~isempty(isq1se)
  32. for jj=1:size(isq1se,1)
  33. xv_min_seq_length(isq1se(jj,1):isq1se(jj,2)-1)=1;
  34. end
  35. end
  36. elseif ismatrix(xv)
  37. if isscalar(min_seq_length)
  38. min_seq_length=repmat(min_seq_length,size(xv,2));
  39. end
  40. xv_min_seq_length=nan(size(xv));
  41. for jj=1:size(xv,2)
  42. [c1ct,i1sct,i1ect,xvmslt]=countconsecutiveones(xv(:,jj),zero_pad,min_seq_length(jj));
  43. isq1s(1:length(i1sct),jj)=i1sct;
  44. isq1e(1:length(i1ect),jj)=i1ect;
  45. c1cv(1:length(c1ct),jj)=c1ct;
  46. xv_min_seq_length(:,jj)=xvmslt;
  47. end
  48. %c1(all(isnan(c1),2),:)=[];
  49. else
  50. error('input must be a vector or matrix');
  51. end