function s=mysort(l) % s=mysort(l) makes s a sorted version of l s = l; % copy unsorted list n = length(s); % number of elements to sort % make sorted lists of length 2 to n for i=2:n v = s(i); % find position for this value j = i; % start at large end % scan up list looking for insertion row while ((j>1) & (s(j-1)>v)) s(j) = s(j-1); % shift larger element down j = j - 1; % go to previous row end; % row j is place for this value s(j) = v; % store in right place end;