File Exchange

image thumbnail

Merge two sorted vectors into a sorted vector

version (2.62 KB) by Dr. Murtaza Khan
Merge two sorted vectors 'a' and 'b' into a sorted vector 'c'


Updated 09 Jul 2009

View License

If we have two individually sorted vectors "a" and "b" but they are not sorted with respect to each other and we want to merge them into vector "c" such that "c" is also a sorted vector. Then c=mergesorted(a,b) can be used.

This function most likely make difference for very large vectors (may be elements in million). On P-4 machine when length of "a" is 2 million and length of "b" is 2.5 million then c=mergesorted(a,b) is around 3 times faster than using MATLAB builtin function c=sort([a,b]).

A simple test program to that test "mergesorted" and builtin "sort" function and compare their performance.

Comments and Ratings (1)

Jhonty R.

very helpful to implement Merge-Sort algorithm


BSD License

MATLAB Release Compatibility
Created with R14SP1
Compatible with any release
Platform Compatibility
Windows macOS Linux