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

insertion(x)
function [y, I]  = insertion(x)
% insertion   tri par insertion
%   function x = insertion(x)

twoOutputs = nargout == 2;
x = x(:);
n = length(x);
I = [];
y = [];
x = x(1:n);
for e = x'
  i = find(e<y);
  if i == []
    y = [ y ; e];
    I = [ I  length(y)];
  else
    y = [y(1:i(1)-1);e;y(i(1):length(y))];
    I = [I(1:i(1)-1),length(y), I(i(1):length(y)-1)];
  end;
end; 

Contact us at files@mathworks.com