No BSD License  

Highlights from
Introduction à Matlab (deuxième édition)

from Introduction à Matlab (deuxième édition) by Jean-Thierry
tous les m-fichiers relatifs à la deuxième édition de l'Introduction à Matlab

merge(x1, x2)
function y = merge(x1, x2)                                          
                                                                    
if nargin == 1                                                      
  x1 = x1(:);                                                       
  if length(x1) > 1                                                 
    mid = fix(length(x1)/2);                                        
    y = merge( merge(x1(1:mid)), merge(x1(mid+1:length(x1))) );     
  else                                                              
    y = x1;                                                         
  end;                                                              
else                                                                
  i1 = 1; i2 = 1; i = 1;                                            
  y = zeros(length(x1)+length(x2),1);                               
  while 1
    if (i1 > length(x1)) | (i2 > length(x2))                     
      break;
    end;
    if x1(i1) <= x2(i2)                                             
      y(i) = x1(i1); 
      i1 = i1+1;                                     
    else                                                            
      y(i) = x2(i2); 
      i2 = i2+1;                                     
    end;                                                            
    i = i+1;                                                        
  end;                                                              
  y(i:length(y)) = [x1(i1:length(x1)) ; x2(i2:length(x2))] ;        
end; 

Contact us at files@mathworks.com