Browse Source

Updated interval returning functions

Ioannis Agtzidis 5 years ago
parent
commit
1c0845c59e
2 changed files with 40 additions and 19 deletions
  1. 39 0
      GetIntervalsIndex.m
  2. 1 19
      GetIntervalsIndexArff.m

+ 39 - 0
GetIntervalsIndex.m

@@ -0,0 +1,39 @@
+% function GetIntervalsIndex:
+%
+% Uses the data along with a data value and returns the intervals (as indices) 
+% for the provided value
+%
+% input:
+%   data       - is a data vector
+%   value      - value to use for intervals calculation
+%
+% output:
+%   intervals  - nx2 array (start index, end index)
+
+function [intervals] = GetIntervalsIndex(data, value)
+    assert(size(data,1) == 1 | size(data,2) == 1, 'Data should be a vector');
+    % initialize data
+    intervals = zeros(0,2);
+
+    % find position of attribute in data
+
+    startIndex = -1;
+    for i=1:size(data,1)
+        if (data(i)==value)
+            % first element of interval
+            if (startIndex==-1)
+                startIndex=i;
+            end
+        else
+            % interval finished on previous iteration
+            if (startIndex~=-1)
+                intervals = [intervals; startIndex i-1];
+            end
+            startIndex = -1;
+        end
+    end
+    % add last interval
+    if (startIndex~=-1)
+        intervals = [intervals; startIndex length(data)];
+    end
+end    

+ 1 - 19
GetIntervalsIndexArff.m

@@ -20,23 +20,5 @@ function [intervals] = GetIntervalsIndexArff(data, arffAttributes, attribute, mo
     % find position of attribute in data
     dataIndex = GetAttPositionArff(arffAttributes, attribute);
 
-    startIndex = -1;
-    for i=1:size(data,1)
-        if (data(i,dataIndex)==moveId)
-            % first element of interval
-            if (startIndex==-1)
-                startIndex=i;
-            end
-        else
-            % interval finished on previous iteration
-            if (startIndex~=-1)
-                intervals = [intervals; startIndex i-1];
-            end
-            startIndex = -1;
-        end
-    end
-    % add last interval
-    if (startIndex~=-1)
-        intervals = [intervals; startIndex size(data,1)];
-    end
+    intervals = GetIntervalsIndex(data(:,dataIndex), moveId);
 end