n=100; x=randn(1,1000); tic, for i=1:n, [sorted1, index1]=sort(x); end, time1=toc; tic, for i=1:n, [sorted2, index2]=sortMex(x); end, time2=toc; fprintf('time by sort = %f sec\n', time1); fprintf('time by sortMex = %f sec\n', time2); fprintf('diff in sorted = %g, diff in index = %g\n', sum(sum(abs(sorted1-sorted2))), sum(sum(abs(index1-index2))));