Code covered by the BSD License  

Highlights from
Merge sorted arrays

4.5

4.5 | 2 ratings Rate this file 23 Downloads (last 30 days) File Size: 8.37 KB File ID: #28930

Merge sorted arrays

by

 

03 Oct 2010 (Updated )

Given two already sorted arrays, the function combines them in an unique sorted array

| Watch this File

File Information
Description

Using this function avoids to call Matlab SORT(), which does unnecessary work since the two inputs is already sorted.

Mex implementation for speed.
'rows' option supported

Acknowledgements

This file inspired Choose K.

MATLAB release MATLAB 7.11 (R2010b)
Other requirements Mex installed
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
02 Nov 2013 Bruno Luong

Hi Paul, you are right this is a BUG. Submission including correction is pending.

01 Nov 2013 Paul

Hi Bruno, thanks for a useful tool. It comes in handy for efficiently summing sparse tensors together. On my system there appears to be a bug when one of the two arrays is empty (see example case below). Is this a compilation problem on my system or a bug in the algorithm? Thanks!

>> [C idx]=mergesa([],[1 1 1; 3 1 1],'rows')

C =

1 1 1
3 1 1

idx =

-1
-2
-3

19 Jan 2012 Jan Simon

@Tal: C++ comments are accepted in the C99 style. Only C89 does not consider them, but this standard is 23 years old now.

28 Mar 2011 Tal Darom

it works.
note that the .c files have c++ comments, resulting in errors when compiled with gcc.

file names should be changed to .cpp or use a c style comments.

Updates
04 Oct 2010

Optionally return the splitting locations of the inputs

31 Oct 2010

Minor speed improvement

04 Nov 2013

Fix bug of merge rows with empty array

Contact us