Skip to content
Snippets Groups Projects
Commit 389c33c0 authored by Josef Kamleitner's avatar Josef Kamleitner
Browse files

fixed bug in input variable check, structured code; no change in how the function works

git-svn-id: https://spcsvn.epfl.ch/repos/TCV/gdat/trunk@3931 d63d8f72-b253-0410-a779-e742ad2e26cf
parent 819cc824
No related branches found
No related tags found
No related merge requests found
......@@ -10,32 +10,66 @@ function [t,i1,i2,i12,t1no,t2no,i1no,i2no]=common_ece(t1,t2,tol,mode,bounds)
% mode: 'a' all or 'n' nearest matches
% bounds: [bmin,bmax] limits search interval for t1
if exist('tol')==0,tol=eps;end
if exist('bounds')==0,bounds=[min([min(t1),min(t2)])-tol;max([max(t2),max(t1)])+tol];end
if exist('mode')==0,mode='n';end
i1=zeros(size(t1));i2=zeros(size(t2));t=[];i12=zeros(size(t1));
t1no=[];t2no=[];i1no=[];i2no=[];match=0;
for j=1:length(t1);
if t1(j)>=bounds(1) & t1(j)<=bounds(2)
tt1=t1(j)*ones(size(t2));
ii2=find(abs(t2-tt1)<=tol);
if (mode=='n') & length(ii2)>0
if (length(ii2)>1),[x,ii2]=min(abs(t2-tt1));end
match=match+1;i2(ii2)=ii2;i1(j)=ii2;i12(j)=ii2;
end
if (mode=='a' & ii2~=[]),match=match+1;i1(j)=j;i12=ii2(1);i2(ii2)=ii2;end
end
if(nargin<3 || ~exist('tol','var'))
tol=eps;
end
if(nargin<4 || ~exist('bounds','var'))
bounds=[min([min(t1),min(t2)])-tol;
max([max(t2),max(t1)])+tol];
end
if(nargin<5 || ~exist('mode','var'))
mode='n';
end
i1=zeros(size(t1));
i2=zeros(size(t2));
t=[];
i12=zeros(size(t1));
t1no=[];
t2no=[];
match=0;
for j=1:length(t1)
if(t1(j)>=bounds(1) && t1(j)<=bounds(2))
tt1=t1(j)*ones(size(t2));
ii2=find(abs(t2-tt1)<=tol);
if(strcmp(mode,'n') && ~isempty(ii2))
if (length(ii2)>1)
[~,ii2]=min(abs(t2-tt1));
end
match=match+1;
i2(ii2)=ii2;
i1(j)=ii2;
i12(j)=ii2;
end
if(strcmp(mode,'a') && ~isempty(ii2))
match=match+1;
i1(j)=j;
i12=ii2(1);
i2(ii2)=ii2;
end
end
end
%disp(['matches found: ',int2str(match)])
%keyboard
i1no=find(i1==0);
i2no=find(i2==0);
i1=find(i1~=0);
i2=find(i2~=0);
if length(i1)>0,t=t1(i1);end
if length(i1no)>0,t1no=t1(i1no);end
if length(i2no)>0,t2no=t2(i2no);end
i1no=find(i1==0);
i2no=find(i2==0);
i1=find(i1~=0);
i2=find(i2~=0);
if(~isempty(i1))
t=t1(i1);
end
if(~isempty(i1no))
t1no=t1(i1no);
end
if(~isempty(i2no))
t2no=t2(i2no);
end
%keyboard
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment