Matlab: Sql-style Join Operation
I would like to do an SQL-style join with Matlab. I could do it by creating datasets (stats toolbox), doing the join, converting back and deleting the datasets again: A1 = [10 10 2
Solution 1:
For your example, you could simply use ISMEMBER:
[~,loc] = ismember(A1,B1);
dsA = [B1(loc) B2(loc)]
result:
dsA =
10 1
10 1
20 2
20 2
30 3
30 3
50 5
50 5
Note: this assumes that all the elements in A1 are found in B1. If that not always the case, you could use the first output of ISMEMBER to filter the zero-values in loc...
Post a Comment for "Matlab: Sql-style Join Operation"