home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 4.ddi / OPTIM.DI$ / V2SORT.M < prev   
Encoding:
Text File  |  1993-03-11  |  711 b   |  31 lines

  1. function v2=v2sort(v1,v2)
  2. %V2SORT Sorts two vectors and then removes missing elements.
  3. %    Given two complex vectors v1 and v2, v2 is returned with
  4. %       the nearest elements which are missing from v1 removed.
  5. %     Syntax:  v2=V2SORT(v1,v2) 
  6.  
  7. lv1=length(v1);
  8. lv2=length(v2);
  9. lv2init=lv2;
  10. v1ones=ones(1,lv1);
  11. v2ones=ones(lv2,1);
  12. diff=abs((v2ones*v1.')-(v2*v1ones));
  13. if lv1>lv2
  14.     temp=min(diff);
  15.     [dum,ind]=sort(-temp);
  16.     for i=1:lv1-lv2
  17.             i2=min([lv2,ind(i)-1]);
  18.             if ind(i)-1<=lv2init & i<lv2init
  19.             v2=[v2(1:i2);v1(ind(i));v2(i2+1:lv2)];
  20.         else
  21.              v2=[v2;v1(lv2+1)];
  22.         end
  23.         lv2=lv2+1;
  24. end
  25. else
  26.     temp=min(diff');
  27.     [dum,ind]=sort(-temp);
  28.     v2(ind(1:lv2-lv1))=[];
  29. end
  30.  
  31.