File Exchange

image thumbnail

Merge matrices

version 1.0 (2.99 KB) by

(in a SQL equijoin)



View License

Function JOINMAT implements SQL 'join' operation with a single equality condition.

It has been tested with numeric keys only, and not optimized; improvements are enthusiastically welcomed.

See also the dataset-array version JOINDST.

PS. Note that output rows are sorted, and Inf values are treated in the same way as (but are distinguished from) NaN values.

Comments and Ratings (3)

David Divad

Unfortunately this does not seem to work always well.


A = [1 1; 1 2; 1 3; 1 4]
C = [1 8; 1 9]
joinmat(A,C,'inner') % does not give cartesian product -> joinmat only works with unique keys in at least one of the matrices

ans =

1 1 8
1 2 9
1 3 8
1 4 9
1 1 8
1 2 9
1 3 8
1 4 9

Does anybody know a good alternative to this? How can I join two matrices in MATLAB (without unique keys)?

Brilliant - this saved me a ton of time from either setting up mySQL or otherwise exporting out of Matlab elsewhere to do the join. Again, brilliant.

Phil from AL

Just what I was looking for. Wonder why MW released a 'join' (kinda) for datasets but not for matrices.




MATLAB Release
MATLAB 7.4 (R2007a)

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

» Watch video