diff --git a/crpptbx/TCV/private/common_ece.m b/crpptbx/TCV/private/common_ece.m index 941fbb1cd8bfb84ea8845f3f285b8d193b1d5d5b..62bee6dabc6454b4198c12fcf81b3ecd33279675 100755 --- a/crpptbx/TCV/private/common_ece.m +++ b/crpptbx/TCV/private/common_ece.m @@ -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