diff --git a/matlab/ep/extended_path.m b/matlab/ep/extended_path.m
index beda19f108b662d292e60dae788cf11685fe6327..806880e87390b7101cb87bfc602e0ab6995be409 100644
--- a/matlab/ep/extended_path.m
+++ b/matlab/ep/extended_path.m
@@ -230,15 +230,13 @@ while (t<sample_size)
             end
             % Test if periods is big enough.
             delta = 0;
-            if ~isempty(idx)
-                delta = max(max(abs(tmp(idx,end-options_.ep.lp:end)./tmp(idx, ...
-                                                                  end-options_.ep.lp-1:end-1)-1)));
-            end;
-            if ~isempty(indx)
-                delta = max(delta,max(max(abs(tmp(indx,end-options_.ep.lp: ...
-                                                  end)-tmp(indx,end-options_.ep.lp-1:end-1)))));
+            if length(tmp)>1 && ~isempty(idx)
+                delta = max(max(abs(tmp(idx,end-options_.ep.lp:end)./tmp(idx,end-options_.ep.lp-1:end-1)-1)));
             end
-            if ~increase_periods &&  delta < options_.dynatol.x
+            if length(tmp)>1 && ~isempty(indx)
+                delta = max(delta,max(max(abs(tmp(indx,end-options_.ep.lp:end)-tmp(indx,end-options_.ep.lp-1:end-1)))));
+            end
+            if ~increase_periods &&  delta<options_.dynatol.x
                 break
             else
                 options_.periods = options_.periods + options_.ep.step;