File Exchange

image thumbnail

Merge sorted arrays

version 1.3 (8.37 KB) by

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

5 Downloads

Updated

View License

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

Comments and Ratings (4)

Bruno Luong

Bruno Luong (view profile)

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

Paul

Paul (view profile)

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

Jan Simon

Jan Simon (view profile)

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

Tal Darom

Tal Darom (view profile)

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

1.3

Fix bug of merge rows with empty array

1.2

Minor speed improvement

1.1

Optionally return the splitting locations of the inputs

MATLAB Release
MATLAB 7.11 (R2010b)
Acknowledgements

Inspired: ChooseK

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video