problems with a one-to-many join using a look up table
조회 수: 6 (최근 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!