Insertion Sort MatLab Function

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

You are now following this Submission

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

Cite As

Mehdi Goudarzi (2026). Insertion Sort MatLab Function (https://www.mathworks.com/matlabcentral/fileexchange/39528-insertion-sort-matlab-function), MATLAB Central File Exchange. Retrieved .

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0.0