problems with a one-to-many join using a look up table

1 view (last 30 days)
I have two datasets which I want to concatenate horizontally, for example:
A=[12 432 245 3000 500]
b=[3000 500 6.2 4.3 1.5]
I need to match b to A based on the last two columns of a and first two of b, so the answer would be:
c=[12 432 245 3000 500 3000 500 6.2 4.3 1.5]
A and b are different sizes. With A containing repeated values of the last two columns and b is acting as a look up table with all possible values.
I basically want to search through A and when number in column 4 and 5 is the same as the numbers in b column 1 and 2 I want to append the following values in b (a one-to-many join)
I hope that made sense, any help would be appreciated
  2 Comments
the cyclist
the cyclist on 8 May 2014
Edited: the cyclist on 8 May 2014
Definitely not clear to me. For the single example you give
c = [A,b]
seems to be what you say you want. But, I'm guessing that is not really what you want.
I think you would be much better off if you post two or three small examples of inputs, and the outputs that you want from those inputs.
Jan
Jan on 10 May 2014
The physical meaning of the values does not matter. I still do not understand what you want to achieve. Please show an example, where "multiple entries in A which share the same Indexes".

Sign in to comment.

Answers (1)

the cyclist
the cyclist on 9 May 2014
I don't have time to think about a full-blown solution right now, but let me suggest you take a look at the ismember() command, and in particular the 'rows' option. This command should allow you to identify rows that are common between A and b, which you can then concatenate. Type
doc ismember
in the command window to see the documentation.
  2 Comments
Lucy
Lucy on 9 May 2014
Thanks for the advice, I will take a look at this command
the cyclist
the cyclist on 9 May 2014
Just finding a few more minutes to think about your problem. I think, but I am not sure, that you want to do something like
[tf,idx] = ismember(b(:,[1 2]),A(:,[4 5]),'rows')
to identify the rows where the first two columns of b are included in the last two columns of A.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!