GetIntervalsIndexArff.m 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. % function GetIntervalsIndexArff:
  2. %
  3. % Uses the data loaded from an ARFF file along with an attribute name and type
  4. % of eye movement and returns the intervals (as indices) for the specific eye
  5. % movement.
  6. %
  7. % input:
  8. % data - data loaded from ARFF file with LoadArff
  9. % arffAttributes - attributes returned from LoadArff
  10. % attribute - attribute to consider for interval counting
  11. % moveId - id for eye movement to consider
  12. %
  13. % output:
  14. % intervals - nx2 array (start index, end index)
  15. function [intervals] = GetIntervalsIndexArff(data, arffAttributes, attribute, moveId)
  16. % initialize data
  17. intervals = zeros(0,2);
  18. % find position of attribute in data
  19. dataIndex = GetAttPositionArff(arffAttributes, attribute);
  20. startIndex = -1;
  21. for i=1:size(data,1)
  22. if (data(i,dataIndex)==moveId)
  23. % first element of interval
  24. if (startIndex==-1)
  25. startIndex=i;
  26. end
  27. else
  28. % interval finished on previous iteration
  29. if (startIndex~=-1)
  30. intervals = [intervals; startIndex i-1];
  31. end
  32. startIndex = -1;
  33. end
  34. end
  35. % add last interval
  36. if (startIndex~=-1)
  37. intervals = [intervals; startIndex size(data,1)];
  38. end
  39. end