problems with a one-to-many join using a look up table
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
the cyclist
2014-5-8
编辑:the cyclist
2014-5-8
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
2014-5-10
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".
回答(1 个)
the cyclist
2014-5-9
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 个评论
the cyclist
2014-5-9
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!