FindDuration.m 852 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. function out = FindDuration(indx);
  2. %FINDDURATION
  3. % Usage: out = FindDuration(indx)
  4. %
  5. % This is a short little function that finds a jump in the indx vector
  6. % and then spits out the number of elements before that jump. It does
  7. % this for all jumps it finds. By a jump, I mean a discontinutity in the
  8. % index. For example, if the index vector is [1 2 3 4 5 8 9 10], there is
  9. % a jump between 5 and 8.
  10. %Written by Dan Valente
  11. %October 2007
  12. if isempty(indx)
  13. out = [];
  14. return;
  15. end
  16. m = 1;
  17. list = [];
  18. indx(end+1)=-1; %Makes sure last section of indx (past final juump) is properly considered.
  19. for i = 1:length(indx)-1;
  20. if indx(i)+1 == indx(i+1)
  21. list = [list i];
  22. else
  23. list = [list i];
  24. out(m) = length(list);
  25. list = [];
  26. m = m+1;
  27. end
  28. end