4.0

4.0 | 1 rating Rate this file 8 Downloads (last 30 days) File Size: 1.12 KB File ID: #39528
image thumbnail

Insertion Sort MatLab Function

by

 

[output] is an array of number which is the sorted version of [input].

| Watch this File

File Information
Description

  You can simply copy and paste this function to the folder you keep your function m-files.
  Insertion Sort is of n^2 order and performs well for up to 10,000 inputs.
  Examples of how you can use this function include, but aren't limited to:

1.
plot(floor(100 * rand(1,100))); hold on;
plot(insertion_sort(floor(100 * rand(1,100))),'r');

2.
a = insertion_sort([1 2 3 2 1 2 3 5 4 3 2 1 4 6 8])

I would appreciate your suggestions, further examples, comments and criticisms.

Best Regards
Mehdi

Required Products MATLAB
MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
04 Jan 2013 wenwu

I am wondering what's the difference or advantage of this submitted code over the built-in function 'sort', which has more functionality?

26 Dec 2012 Jan Simon

The most important improvement would be a documentation: The first comment section after the "function ..." line is displayed by the "help" command. Without a documentation, which explains e.g. the type and dimensions of inputs and outputs as well as the applied procedure, a function is not usable, although it might be useful.

Look at Matlab's toolbox functions to learn more about the usual documentation style, e.g. the "H1-line".

Contact us