From 6553b9ec6fed5bfc96cb2a54fbe11df404028e8b Mon Sep 17 00:00:00 2001
From: marwan <>
Date: Wed, 16 Mar 2005 11:23:52 +0000
Subject: [PATCH] automatic detection: * of provided time-scale * if
 multi-column input can be used as phase-space vector

---
 crqa.m | 392 +++++++++++++++++++++++++++++++++------------------------
 1 file changed, 231 insertions(+), 161 deletions(-)

diff --git a/crqa.m b/crqa.m
index 337117f..a80e103 100644
--- a/crqa.m
+++ b/crqa.m
@@ -71,16 +71,16 @@ function xout=crqa(varargin)
 %    Parameters not needed to be specified.
 %
 %    Output:
-%      Y(:,1)=RR     (recurrence rate)
-%      Y(:,2)=DET    (determinism)
-%      Y(:,3)=<L>    (mean diagonal line length)
-%      Y(:,4)=Lmax   (maximal diagonal line length)
-%      Y(:,5)=ENTR   (entropy of the diagonal line lengths)
-%      Y(:,6)=LAM    (laminarity)
-%      Y(:,7)=TT     (trapping time)
-%      Y(:,8)=Vmax   (maximal vertical line length)
-%      Y(:,9)=T1     (recurrence time of 1st type)
-%      Y(:,10)=T2    (recurrence time of 2nd type)
+%      Y(:, 1) = RR     (recurrence rate)
+%      Y(:, 2) = DET    (determinism)
+%      Y(:, 3) = <L>    (mean diagonal line length)
+%      Y(:, 4) = Lmax   (maximal diagonal line length)
+%      Y(:, 5) = ENTR   (entropy of the diagonal line lengths)
+%      Y(:, 6) = LAM    (laminarity)
+%      Y(:, 7) = TT     (trapping time)
+%      Y(:, 8) = Vmax   (maximal vertical line length)
+%      Y(:, 9) = T1     (recurrence time of 1st type)
+%      Y(:,10) = T2     (recurrence time of 2nd type)
 %
 %    Warning:
 %    The RQA measures may differ from those of the RQA programmes by
@@ -90,17 +90,17 @@ function xout=crqa(varargin)
 %    with the maximal phase space diameter, which can be estimated 
 %    with the programme PSS:
 %
-%      RQA=crqa(100*x/pss(x,dim,lag,'euclidean'),...
+%      RQA = crqa(100*x/pss(x,dim,lag,'euclidean'),...
 %               dim,lag,e,[],[],l_min,v_min,1,...
 %               'euclidean','nonormalize','silent')
 %
-%    Examples: a=randn(300,1);
+%    Examples: a = randn(300,1);
 %              crqa(a,1,1,.2,40,2,'euc')
 %
-%              N=500; w=40; ws=2;
-%              a=3.4:.6/(N-1):4;
-%              b=.5; for i=2:N, b(i)=a(i)*b(i-1)*(1-b(i-1));end
-%              y=crqa(b,3,2,.1,w,ws);
+%              N = 500; w = 40; ws = 2;
+%              a = 3.4:.6/(N-1):4;
+%              b = .5; for i = 2:N, b(i) = a(i)*b(i-1)*(1-b(i-1)); end
+%              y = crqa(b,3,2,.1,w,ws);
 %              subplot(2,1,1), plot(a,b,'.','markersize',.1)
 %              title('logistic map'), axis([3.4 4 0 1])
 %              subplot(2,1,2), plot(a(1:ws:N-w),y(1:ws:N-w,1))
@@ -135,6 +135,9 @@ function xout=crqa(varargin)
 % $Revision$
 %
 % $Log$
+% Revision 5.9  2004/12/23 07:49:03  marwan
+% bug in order patterns RP fixed (empty order patterns)
+%
 % Revision 5.8  2004/11/15 12:56:01  marwan
 % bug fix in method checking
 %
@@ -167,6 +170,8 @@ vmin=2;
 nonorm=1;
 theiler_window=1;
 hw=-1;
+xscale = [];
+yscale = [];
 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% check the input
@@ -189,11 +194,11 @@ errcode=1;
    i_char=find(cellfun('isclass',varargin,'char'));
    t=1;
    w=[];wstep=0; method='max'; method_n=1;
-   embed_flag=1;
+   time_scale_flag=1; time_scale_flag_x=1;
    nogui=0;
-      check_meth={'ma','eu','mi','nr','fa','in','om','op','di'}; 	% maxnorm, euclidean, nrmnorm,  fan, distance
-      check_gui={'gui','nog','sil'};		% gui, nogui, silent
-      check_norm={'non','nor'};			% nonormalize, normalize
+      check_meth={'ma','eu','mi','nr','fa','in','om','op','di'};         % maxnorm, euclidean, nrmnorm,  fan, distance
+      check_gui={'gui','nog','sil'};                % gui, nogui, silent
+      check_norm={'non','nor'};                        % nonormalize, normalize
    
    if nargin & ischar(varargin{1})
      set(0,'ShowHidden','on');h=findobj('Tag','Msgbox_Check Input');delete(h)
@@ -201,6 +206,10 @@ errcode=1;
      h=findobj('Tag','crqa_Fig');
      temp=get(h(1),'UserData');
      x=temp{1}; y=temp{2};
+     h=findobj('Tag','crqa_axes_Data','Parent',h(1)); % get handle of plot-axes object
+     h_crqa_axes_Data = h(1);
+     h=findobj('Type','line','Parent',h(1)); % get handle of line-object
+     xscale=get(h(1),'xdata');
      h=findobj('Tag','crqa_m');
      m=str2num(get(h(1),'String'));
      h=findobj('Tag','crqa_maxLag');
@@ -221,7 +230,7 @@ errcode=1;
      w=str2num(get(h(1),'String'));
      h=findobj('Tag','crqa_ws');
      wstep=str2num(get(h(1),'String'));
-     
+
    elseif nargin & isnumeric(varargin{1})
 
      % check the text input parameters for method, gui 
@@ -263,13 +272,13 @@ errcode=1;
       % get the parameters for creating RP
       if max(size(varargin{1}))<=3
          disp('Error using ==> crqa')
-	 disp('To less values in data X.')
-	 return
+         disp('To less values in data X.')
+         return
       end
       x=double(varargin{1});
       if isempty(varargin{2}) | ~isnumeric(varargin{2}), y=x; else
       y=double(varargin{2}); end
-%      if sum(double(diff(x(:,1))<=0)), embed_flag=0; end
+%      if sum(double(diff(x(:,1))<=0)), time_scale_flag=0; end
    
       if (isnumeric(varargin{2}) & max(size(varargin{2}))==1) | ~isnumeric(varargin{2})
         y=x;
@@ -304,94 +313,129 @@ errcode=1;
    
    if size(x,2)>=2
       xscale=x(:,1); 
-      if ~isempty(find(diff(xscale)<0)), embed_flag=0; end
+      if ~isempty(find(diff(xscale)<0)) % multi-column data vector, each column used as vector component
+          time_scale_flag=0; 
+          time_scale_flag_x=0; 
+          xscale=(1:length(x))'; 
+      end
    else
       xscale=(1:length(x))'; 
+      time_scale_flag=0; 
+      time_scale_flag_x=0; 
    end
+
    if size(y,2)>=2
       yscale=y(:,1); 
-      if ~isempty(find(diff(yscale)<0)), embed_flag=0; end
+      time_scale_flag=1; 
+      if ~isempty(find(diff(yscale)<0))
+          time_scale_flag=0; 
+          yscale=(1:length(y))';
+      end
+      if time_scale_flag && ~time_scale_flag_x % if time-scale given in y, but not in x -> error
+          if ~nogui
+             errordlg(['A time-scale for the second data is series given, but not for the first!',10,'(The time-scale has to be inlcuded as the first colummn of the first data vector.)'],'Check Data')
+             waitforbuttonpress
+             return
+          else
+             error(['A time-scale for the second data series is given, but not for the first!',10,'(The time-scale has to be inlcuded as the first colummn of the first data vector.)'])
+          end
+      end
    else
        yscale=(1:length(y))';
+       time_scale_flag=0; 
    end
-      
-      if max(size(x))~=max(size(y)),
+   if time_scale_flag_x && ~time_scale_flag % if time-scale given in x, but not in y
+       if length(x) ~= length(y)
+          if ~nogui
+             errordlg(['If you are using the time-scale given by the first vector also for',10,'the second vector, both vectors should have the same size!'],'Check Data')
+             waitforbuttonpress
+             return
+          else
+             error(['If you are using the time-scale given by the first vector also for',10,'the second vector, both vectors should have the same size!'])
+          end
+       end
+       y = [xscale, y];
+       yscale = xscale;
+       time_scale_flag=1; 
+   end
+   
+   if max(size(x))~=max(size(y)),
         if ~nogui, errordlg('Data must have the same length.','Check Data'), waitforbuttonpress, else error('Data must have the same length.'), end
-      end
-      if e<0, 
+   end
+   if e<0, 
         e=1; 
-	if ~nogui
-	   warndlg('The threshold size E can not be negative and is now set to 1.','Check Data')
-	   waitforbuttonpress
-	   h=findobj('Tag','crqa_eps');
-	   if ~isempty(h), set(h(1),'String',num2str(e)), end
+        if ~nogui
+           warndlg('The threshold size E can not be negative and is now set to 1.','Check Data')
+           waitforbuttonpress
+           h=findobj('Tag','crqa_eps');
+           if ~isempty(h), set(h(1),'String',num2str(e)), end
         else 
-	   disp('The threshold size E can not be negative and is now set to 1.'), 
+           disp('The threshold size E can not be negative and is now set to 1.'), 
         end
       end
       if t<1, 
         t=1; 
-	if ~nogui
-	   warndlg('The delay T can not be smaller than one and is now set to 1.','Check Data')
-	   waitforbuttonpress
-	   h=findobj('Tag','crqa_maxLag');
-	   if ~isempty(h), set(h(1),'String',num2str(t)), end
-	else
-	   disp('The delay T can not be smaller than one and is now set to 1.')
-	end
+        if ~nogui
+           warndlg('The delay T can not be smaller than one and is now set to 1.','Check Data')
+           waitforbuttonpress
+           h=findobj('Tag','crqa_maxLag');
+           if ~isempty(h), set(h(1),'String',num2str(t)), end
+        else
+           disp('The delay T can not be smaller than one and is now set to 1.')
+        end
       end
       if isempty(w), w=Nx; wstep=1; end
       if w < 5+(m-1)*t, 
         w=5+(m-1)*t;
-	if ~nogui, warndlg('The window size W exceeds the valid range.','Check Data')
-	   waitforbuttonpress
-	   h=findobj('Tag','crqa_w');
-	   if ~isempty(h), set(h(1),'String',num2str(w)), end
-	else, disp('The window size W exceeds the valid range.'), end
+        if ~nogui, warndlg('The window size W exceeds the valid range.','Check Data')
+           waitforbuttonpress
+           h=findobj('Tag','crqa_w');
+           if ~isempty(h), set(h(1),'String',num2str(w)), end
+        else, disp('The window size W exceeds the valid range.'), end
       end
       if w>Nx, 
         w=Nx; wstep=1;; 
-	if ~nogui, warndlg('The window size W exceeds the valid range.','Check Data')
-	   waitforbuttonpress
-	   h=findobj('Tag','crqa_w');
-	   if ~isempty(h), set(h(1),'String',num2str(w)), end
-	else, disp('The window size W exceeds the valid range.'), end
+        if ~nogui, warndlg('The window size W exceeds the valid range.','Check Data')
+           waitforbuttonpress
+           h=findobj('Tag','crqa_w');
+           if ~isempty(h), set(h(1),'String',num2str(w)), end
+        else, disp('The window size W exceeds the valid range.'), end
       end
       if wstep<1 | wstep>Nx/3, 
         wstep=2; 
-	if ~nogui, warndlg('The window shifting value WS exceeds the valid range.','Check Data')
-	   waitforbuttonpress
-	   h=findobj('Tag','crqa_ws');
-	   if ~isempty(h), set(h(1),'String',num2str(wstep)), end
-	else, disp('The window shifting value WS exceeds the valid range.'), end
+        if ~nogui, warndlg('The window shifting value WS exceeds the valid range.','Check Data')
+           waitforbuttonpress
+           h=findobj('Tag','crqa_ws');
+           if ~isempty(h), set(h(1),'String',num2str(wstep)), end
+        else, disp('The window shifting value WS exceeds the valid range.'), end
       end
       if vmin<1 | vmin>Nx, 
         vmin=2; 
-	if ~nogui, warndlg('The minimal length for vertical lines is not valid.','Check Data')
-	   waitforbuttonpress
-	   h=findobj('Tag','crqa_vmin');
-	   if ~isempty(h), set(h(1),'String',num2str(vmin)), end
-	else, disp('The minimal length for vertical lines is not valid.'), end
+        if ~nogui, warndlg('The minimal length for vertical lines is not valid.','Check Data')
+           waitforbuttonpress
+           h=findobj('Tag','crqa_vmin');
+           if ~isempty(h), set(h(1),'String',num2str(vmin)), end
+        else, disp('The minimal length for vertical lines is not valid.'), end
       end
       if lmin<1 | lmin>Nx, 
         lmin=2; 
-	if ~nogui, warndlg('The minimal length for diagonal lines is not valid.','Check Input')
-	   waitforbuttonpress
-	   h=findobj('Tag','crqa_lmin');
-	   if ~isempty(h), set(h(1),'String',num2str(lmin)), end
-	else, disp('The minimal length for diagonal lines is not valid.'), end
+        if ~nogui, warndlg('The minimal length for diagonal lines is not valid.','Check Input')
+           waitforbuttonpress
+           h=findobj('Tag','crqa_lmin');
+           if ~isempty(h), set(h(1),'String',num2str(lmin)), end
+        else, disp('The minimal length for diagonal lines is not valid.'), end
       end
       if theiler_window<0 | theiler_window>Nx, 
         theiler_window=1; 
-	if ~nogui, warndlg('The value for the Theiler window is not valid.','Check Input')
-	   waitforbuttonpress
-	   h=findobj('Tag','crqa_theiler');
-	   if ~isempty(h), set(h(1),'String',num2str(theiler_window)), end
-	else, disp('The value for the Theiler window is not valid.'), end
+        if ~nogui, warndlg('The value for the Theiler window is not valid.','Check Input')
+           waitforbuttonpress
+           h=findobj('Tag','crqa_theiler');
+           if ~isempty(h), set(h(1),'String',num2str(theiler_window)), end
+        else, disp('The value for the Theiler window is not valid.'), end
       end
       if x~=y, theiler_window=0; end
       t=round(t); m=round(m); w=round(w); wstep=round(wstep); vmin=round(vmin); lmin=round(lmin); theiler_window=round(theiler_window);
-   
+
 switch(action)
 
   
@@ -406,15 +450,15 @@ case 'init'
   scr=get(0,'ScreenSize'); 
   set(0,'Unit',oldunit)
   
-  h8=figure(props.window,...				% Plot Figure
+  h8=figure(props.window,...                                % Plot Figure
             'Tag','crqa_Fig',...
-	    'MenuBar','Figure',...
+            'MenuBar','Figure',...
             'Position',[(scr(3)-150)/2 scr(4)-50 150.0000 44],...
             'PaperType','a4',...
-	    'PaperPosition',[0.25 0.25 7.7677 11.193],...
-	    'PaperOrientation','portrait',...
-	    'UserData',{x,y},...
-  	    'Name','Cross Recurrence Quantification Analysis');
+            'PaperPosition',[0.25 0.25 7.7677 11.193],...
+            'PaperOrientation','portrait',...
+            'UserData',{x,y,time_scale_flag},...
+              'Name','Cross Recurrence Quantification Analysis');
   
   set(0,'showhidden','on')
   h=findobj('Label','&Help','Type','uimenu');
@@ -439,9 +483,9 @@ case 'init'
   set(h,props.logo,'Tag','axes_logo')
   h=uicontrol(props.text,...
             'Tag','text_logo',...
-	    'String','Uni Potsdam',...
+            'String','Uni Potsdam',...
             'Position',[97+30 24.2143+14.5 22  3.5714]);    
-  h2=textwrap(h,{'© AGNLD','University of Potsdam','1998-2004'});
+  h2=textwrap(h,{'© AGNLD','University of Potsdam','1998-2005'});
   set(h,'String',h2)
 
 
@@ -452,18 +496,28 @@ case 'init'
   axes_hoffset = 2.5;
   h=axes(props.axes,...
             'Tag','crqa_axes_Data',...
-	    'Box','On',...
+                'Box','On',...
             'Position',[11.2017  axes_base+4*(axes_height+axes_hoffset)    28.1785+15    axes_height]);    
-  plot(xscale,x,'color',props.line.Color)
-  if ~all(x==y) hold on; plot(yscale,y,'r'), end
+
+  if time_scale_flag
+      plot(xscale,x(:,2:end),'color',props.line.Color)
+      if ~all(x(:)==y(:)) hold on; plot(yscale,y(:,2:end),'r'), end
+  else
+      plot(xscale,x(:,1),'color',props.line.Color)
+      if ~all(x(:)==y(:)) hold on; plot(yscale,y(:,1),'r'), end
+  end
   set(h,'Tag','crqa_axes_Data','color',props.axes.Color)
   ylabel('Data')
 
   h=axes(props.axes,...
             'Tag','crqa_axes_Var',...
-	    'Box','On',...
+            'Box','On',...
             'Position',[49.8023+15   axes_base+4*(axes_height+axes_hoffset)   28.1785+15    axes_height]);    
-  x_var = winplot(x,w,wstep,2);
+  if time_scale_flag
+     x_var = winplot(x(:,2:end),w,wstep,2);
+  else
+     x_var = winplot(x(:,1),w,wstep,2);
+  end
   if size(x_var,1) > 2
     h2=stairs(xscale(round(x_var(:,1))),x_var(:,2));
     set(h2,'color',props.line.Color)
@@ -471,8 +525,13 @@ case 'init'
     cla
     text(0.5,0.5,sprintf('%6.4f',x_var(1,2)),'FontWeight','bold','HorizontalAlign','Center')
   end
-  if ~all(x==y) 
-    hold on; y_var = winplot(y,w,wstep,2); 
+  if ~all(x(:)==y(:)) 
+    hold on; 
+    if time_scale_flag
+        y_var = winplot(y(:,2:end),w,wstep,2); 
+    else
+        y_var = winplot(y(:,1),w,wstep,2); 
+    end
     if size(y_var,1) > 2
       stairs(yscale(round(y_var(:,1))),y_var(:,2),'r')
       h3=axes('Units','Char','Pos',get(h,'Pos'),'XLim',get(h,'XLim'),'YLim',get(h,'YLim'),'YAxisLocation','right','Color','none','Tag','crqa_axes_CoVar','visible','off');
@@ -488,49 +547,49 @@ case 'init'
 
   h=axes(props.axes,...
             'Tag','crqa_axes_RR',...
-	    'Box','On',...
+            'Box','On',...
             'Position',[11.2017   axes_base+3*(axes_height+axes_hoffset)   28.1785+15    axes_height]);    
   ylabel('RR')
 
   h=axes(props.axes,...
             'Tag','crqa_axes_DET',...
-	    'Box','On',...
+            'Box','On',...
             'Position',[49.8023+15   axes_base+3*(axes_height+axes_hoffset)   28.1785+15    axes_height]);    
   ylabel('DET')
 
   h=axes(props.axes,...
             'Tag','crqa_axes_L',...
-	    'Box','On',...
+            'Box','On',...
             'Position',[11.2017   axes_base+2*(axes_height+axes_hoffset)   28.1785+15    axes_height]);    
   ylabel('L')
 
   h=axes(props.axes,...
             'Tag','crqa_axes_ENTR',...
-	    'Box','On',...
+            'Box','On',...
             'Position',[49.8023+15   axes_base+2*(axes_height+axes_hoffset)   28.1785+15    axes_height]);    
   ylabel('ENTR')
 
   h=axes(props.axes,...
             'Tag','crqa_axes_LAM',...
-	    'Box','On',...
+            'Box','On',...
             'Position',[11.2017    axes_base+1*(axes_height+axes_hoffset)   28.1785+15    axes_height]);    
   ylabel('LAM')
 
   h=axes(props.axes,...
             'Tag','crqa_axes_TT',...
-	    'Box','On',...
+            'Box','On',...
             'Position',[49.8023+15    axes_base+1*(axes_height+axes_hoffset)   28.1785+15    axes_height]);    
   ylabel('TT')
 
   h=axes(props.axes,...
             'Tag','crqa_axes_T1',...
-	    'Box','On',...
+            'Box','On',...
             'Position',[11.2017    axes_base+0*(axes_height+axes_hoffset)   28.1785+15    axes_height]);    
   ylabel('T_1')
 
   h=axes(props.axes,...
             'Tag','crqa_axes_T2',...
-	    'Box','On',...
+            'Box','On',...
             'Position',[49.8023+15    axes_base+0*(axes_height+axes_hoffset)   28.1785+15    axes_height]);    
   ylabel('T_2')
 
@@ -542,29 +601,29 @@ case 'init'
   h=uicontrol(props.text,...
             'Tag','text',...
             'Fontangle','italic',...
-	    'String','Embedding parameters',...
+            'String','Embedding parameters',...
             'Position',[87+30 34.2+1.6 16.8333  1.5000]);    
  
   h=uicontrol(props.text,...
             'Tag','text',...
-	    'String','Dimension:',...
+            'String','Dimension:',...
             'Position',[89+30 32+2.2 16.8333  1.5000]);    
 
   h=uicontrol(props.edit,...
             'Tag','crqa_m',...
-	    'String',num2str(m),...
-  	      'ToolTip','Select the embedding dimension.',...
+            'String',num2str(m),...
+                'ToolTip','Select the embedding dimension.',...
             'Position',[104+30 32+.2+2.2 7  1.5000]);    
 
   h=uicontrol(props.text,...
             'Tag','text',...
-	    'String','Delay:',...
+            'String','Delay:',...
             'Position',[89+30 30+2.32 16.8333  1.5000]);    
 
   h=uicontrol(props.edit,...
             'Tag','crqa_maxLag',...
-	    'String',num2str(t),...
-	    'ToolTip','Insert the embedding delay time.',...
+            'String',num2str(t),...
+            'ToolTip','Insert the embedding delay time.',...
             'Position',[104+30 30+.2+2.32 7  1.5000]);    
 
 %%%%%%%%%%% neigbourhood
@@ -575,26 +634,26 @@ case 'init'
   h=uicontrol(props.text,...
             'Tag','text',...
             'Fontangle','italic',...
-	    'String','Neighbourhood',...
+            'String','Neighbourhood',...
             'Position',[87+30 26.8+2.5 23  1.5000]);    
  
   h=uicontrol(props.popup,...
             'Tag','text',...
             'Tag','crqa_method',...
-	    'UserData',nonorm,...
-	    'Value',method_n,...
-	    'String','Maximum Norm|Euclidean Norm|Minimum Norm|Normalized Norm|Fixed Amount|Interdependent|Order Matrix|Order Patterns|Distance Plot',...
+            'UserData',nonorm,...
+            'Value',method_n,...
+            'String','Maximum Norm|Euclidean Norm|Minimum Norm|Normalized Norm|Fixed Amount|Interdependent|Order Matrix|Order Patterns|Distance Plot',...
             'Position',[89+30 24.6+.2+2.5 22  1.7]);    
 
   h=uicontrol(props.text,...
             'Tag','text',...
-	    'String','Threshold:',...
+            'String','Threshold:',...
             'Position',[89+30 22.6+2.5 16.8333  1.5]);    
 
   h=uicontrol(props.edit,...
             'Tag','crqa_eps',...
-	    'String',num2str(e),...
-	    'ToolTip','Insert the size of neighbourhood.',...
+            'String',num2str(e),...
+            'ToolTip','Insert the size of neighbourhood.',...
             'Position',[104+30 22.6+.2+2.5 7  1.5000]);    
 
 %%%%%%%%%%% crqa parameters
@@ -605,63 +664,63 @@ case 'init'
   h=uicontrol(props.text,...
             'Tag','text',...
             'Fontangle','italic',...
-	    'String','CRQA parameters',...
+            'String','CRQA parameters',...
             'Position',[87+30 19.4+2.5 23  1.5000]);    
 
   h=uicontrol(props.text,...
             'Tag','text',...
-	    'String','min. Diagonal:',...
+            'String','min. Diagonal:',...
             'Position',[89+30 17.6+2.5 16.8333  1.5]);    
 
   h=uicontrol(props.edit,...
             'Tag','crqa_lmin',...
-	    'String',num2str(lmin),...
-	    'ToolTip','Insert the minimal length of a diagonal line.',...
+            'String',num2str(lmin),...
+            'ToolTip','Insert the minimal length of a diagonal line.',...
             'Position',[104+30 17.6+.2+2.5 7  1.5000]);    
 
   h=uicontrol(props.text,...
             'Tag','text',...
-	    'String','min. Vertical:',...
+            'String','min. Vertical:',...
             'Position',[89+30 15.6+2.5 16.8333  1.5]);    
 
   h=uicontrol(props.edit,...
             'Tag','crqa_vmin',...
-	    'String',num2str(vmin),...
-	    'ToolTip','Insert the minimal length of a vertical line.',...
+            'String',num2str(vmin),...
+            'ToolTip','Insert the minimal length of a vertical line.',...
             'Position',[104+30 15.6+.2+2.5 7  1.5000]);    
 
   h=uicontrol(props.text,...
             'Tag','text',...
-	    'String','Theiler wind.:',...
+            'String','Theiler wind.:',...
             'Position',[89+30 15.6+.5 16.8333  1.5]);    
 
   h=uicontrol(props.edit,...
             'Tag','crqa_theiler',...
-	    'String',num2str(theiler_window),...
-	    'ToolTip','Insert the size for the Theiler window.',...
+            'String',num2str(theiler_window),...
+            'ToolTip','Insert the size for the Theiler window.',...
             'Position',[104+30 15.6+.2+.5 7  1.5000]);    
   if x~=y; set(h,'enable','off'); end
 
   h=uicontrol(props.text,...
             'Tag','text',...
-	    'String','Window size:',...
+            'String','Window size:',...
             'Position',[89+30 13.6+.5 16.8333  1.5]);    
 
   h=uicontrol(props.edit,...
             'Tag','crqa_w',...
-	    'String',num2str(w),...
-	    'ToolTip','Insert the size of the sliding window.',...
+            'String',num2str(w),...
+            'ToolTip','Insert the size of the sliding window.',...
             'Position',[104+30 13.6+.2+.5 7  1.5000]);    
 
   h=uicontrol(props.text,...
             'Tag','text',...
-	    'String','Window step:',...
+            'String','Window step:',...
             'Position',[89+30 11.6+.5 16.8333  1.5]);    
 
   h=uicontrol(props.edit,...
             'Tag','crqa_ws',...
-	    'String',num2str(wstep),...
-	    'ToolTip','Insert the step width for sliding the window.',...
+            'String',num2str(wstep),...
+            'ToolTip','Insert the step width for sliding the window.',...
             'Position',[104+30 11.6+.2+.5 7  1.5000]);    
 
 
@@ -673,33 +732,33 @@ case 'init'
 
 
  h=uicontrol(props.button,...
-  	      'String','Store',...
-  	      'Tag','crqa_button_store',...
-	      'Enable','Off',...
-  	      'ToolTip','Stores the CRQA analysis into a variable in the workspace.',...
-  	      'Callback','crqa store',...
-  	      'Position',[100.5+30  7.4+.5 10.5  2.2143]);
+                'String','Store',...
+                'Tag','crqa_button_store',...
+              'Enable','Off',...
+                'ToolTip','Stores the CRQA analysis into a variable in the workspace.',...
+                'Callback','crqa store',...
+                'Position',[100.5+30  7.4+.5 10.5  2.2143]);
 
   h=uicontrol(props.button,...
             'Tag','crqa_button_print',...
-	    'CallBack','crqa print',...
-  	      'ToolTip','Prints the CRQA window.',...
-	    'String','Print',...
+            'CallBack','crqa print',...
+                'ToolTip','Prints the CRQA window.',...
+            'String','Print',...
             'Position',[89+30  7.4+.5 10.5  2.2143]);    
 
   h=uicontrol(props.button,...
             'Tag','crqa_button_close',...
-	    'CallBack','crqa close',...
-  	      'ToolTip','Closes the CRQA window.',...
-	    'String','Close',...
+            'CallBack','crqa close',...
+                'ToolTip','Closes the CRQA window.',...
+            'String','Close',...
             'Position',[89+30  2.1+.5 22  2.2143]);    
   
      h=uicontrol(props.button,...
-  	      'String','Apply',...
-  	      'Tag','crqa_button_apply',...
-  	      'ToolTip','Starts the computation.',...
-  	      'Callback','crqa compute',...
-  	      'Position',[89+30  4.75+.5 22  2.2143]);
+                'String','Apply',...
+                'Tag','crqa_button_apply',...
+                'ToolTip','Starts the computation.',...
+                'Callback','crqa compute',...
+                'Position',[89+30  4.75+.5 22  2.2143]);
   
   set(0,'ShowHidden','on')
   set(h8, 'HandleVis','CallBack')
@@ -734,7 +793,7 @@ case 'store'
       crqa_values=get(h(1),'UserData');
       assignin('base',vname, [crqa_values])
       warndlg(['CRQA measures have been assigned to the workspace variable ''',vname,'''.'],'Store output');
-	   waitforbuttonpress
+           waitforbuttonpress
       set(h1(1),'UserData',vname)
     end
   end
@@ -825,15 +884,24 @@ for i=1:wstep:Nx-w;
        end
      end
 
+do_norm = {'non';'nor'};
+
 try
 %  X=crp_big(x(i:i+w-1,:),y(i:i+w-1,:),m,t,e,'fan','silent');
-  if 0 %embed_flag
-    X=crp_big(x(i:i+w-1,:),y(i:i+w-1,:),m,t,e,method,'silent',check_norm{nonorm+1});
+  if time_scale_flag
+    X=crp_big(x(i:i+w-1,:),y(i:i+w-1,:),m,t,e,method,do_norm{nonorm+1},'silent',varargin{i_char});
   else
-    X=crp2(x(i:i+w-1,:),y(i:i+w-1,:),m,t,e,method,'silent',varargin{i_char});
+    X=crp2(x(i:i+w-1,:),y(i:i+w-1,:),m,t,e,method,do_norm{nonorm+1},'silent',varargin{i_char});
   end
 %  X=crp(x(i:i+w-1,:),y(i:i+w-1,:),m,t,e,varargin{i_char},'silent');
-  x_var=var(x(i:i+w-1,:)); y_var=var(y(i:i+w-1,:)); temp=cov(x(i:i+w-1,:),y(i:i+w-1,:)); xy_var=temp(1,2);
+  if time_scale_flag
+     x_var=var(x(i:i+w-1,2:end)); y_var=var(y(i:i+w-1,2:end)); 
+     temp=cov(x(i:i+w-1,2:end),y(i:i+w-1,2:end));
+  else
+     x_var=var(x(i:i+w-1,1)); y_var=var(y(i:i+w-1,1)); 
+     temp=cov(x(i:i+w-1,1),y(i:i+w-1,1));
+  end
+  xy_var=temp(1,2);
 
 warning off 
 if nogui~=2 & ishandle(h1), set(h1,'str',[num2str(i),'/',num2str(Nx-w)]); waitbar(i/(Nx-w)); drawnow, end
@@ -944,34 +1012,34 @@ if ~nogui
     h=findobj('Tag','crqa_axes_T1','Parent',gcf); h_axes.h(7)=h(1);
     h=findobj('Tag','crqa_axes_T2','Parent',gcf); h_axes.h(8)=h(1);
     h=findobj('Tag','crqa_axes_Var','Parent',gcf); h_axes.h(9)=h(1);
-%    if ~all(x==y), h=findobj('Tag','crqa_axes_CoVar','Parent',gcf); h_axes.h(10)=h(1); end
+    if ~all(x(:)==y(:)), h=findobj('Tag','crqa_axes_CoVar','Parent',gcf); h_axes.h(10)=h(1); end
    for i=1:9,
      set(gcf,'CurrentAxes',h_axes.h(i))
      if size(Y,1)==1
        cla
        text(0.5,0.5,sprintf('%6.4f',Y(index(i))),'FontWeight','bold','HorizontalAlign','Center')
-%        if ~all(x==y) & i==9
+%        if ~all(x(:)==y(:)) & i==9
 %          cla 
-% 	     text(0.5,0.5,sprintf('%6.5f, %6.5f',Y(index(i)),Y(index(i+1))),'FontWeight','bold','HorizontalAlign','Center')
-% 	     set(gcf,'CurrentAxes',h_axes.h(i+1));cla
+%              text(0.5,0.5,sprintf('%6.5f, %6.5f',Y(index(i)),Y(index(i+1))),'FontWeight','bold','HorizontalAlign','Center')
+%              set(gcf,'CurrentAxes',h_axes.h(i+1));cla
 %          set(h_axes.h(i+1),'visible','off');
 %        end
      else
        if i==9
          cla
-	     h2=stairs(1:wstep:length(Y),Y(1:wstep:end,index(i)));
-	     set(h2,'color',props.line.Color)
-         if ~all(x==y) 
-	       set(gca,'Color','none')
-           hold on; h2=stairs(1:wstep:length(Y),Y(1:wstep:end,index(10)),'r');
+             h2=stairs(xscale(1:wstep:length(Y)),Y(1:wstep:end,index(i)));
+             set(h2,'color',props.line.Color)
+         if ~all(x(:)==y(:)) 
+           set(gca,'Color','none')
+           hold on; h2=stairs(xscale(1:wstep:length(Y)),Y(1:wstep:end,index(10)),'r');
            set(gcf,'CurrentAxes',h_axes.h(i+1));cla
            set(h_axes.h(10),'visible','on');
-           h3=stairs(1:wstep:length(Y),Y(1:wstep:end,index(11))); set(h3,'color',[0 .4 0]);
+           h3=stairs(xscale(1:wstep:length(Y)),Y(1:wstep:end,index(11))); set(h3,'color',[0 .4 0]);
            ylabel(tx(i+1));
            set(h_axes.h(i+1),'Tag',tags{i+1},'Units','Norm','Color','none','YAxisLocation','right','YColor',[0 .4 0])
          end
        else
-         plot(1:wstep:length(Y),Y(1:wstep:end,index(i)),'color',props.line.Color)
+         plot(xscale(1:wstep:length(Y)),Y(1:wstep:end,index(i)),'color',props.line.Color)
        end
      end
      set(gcf,'CurrentAxes',h_axes.h(i));
@@ -980,6 +1048,8 @@ if ~nogui
    end
    h=findobj('Tag','crqa_button_store');
    set(h(1),'UserData',Y,'Enable','On')
+   xlim = get(h_axes.h(9),'xlim');
+   set(h_crqa_axes_Data,'xlim',xlim)
 else
   if nargout, xout=Y(:,1:10); end
 end
-- 
GitLab