Search in two columns (Tables)

11 次查看(过去 30 天)
Manuel Valenciano
Manuel Valenciano 2016-6-20
Hi, I'm going to explain my problem with a small example of my real problem. My real problem has a bigger size than the following example.
I have two tables with data: Table1_example:
Table2_example:
Table1_example1 and Table1_example2 are the same variables that Table2_example1 and Table2_example2 (Categorical data).
I want to search the values in Table1_example in Table2_example and obtein the following final table:
TableObjective_example:
Thank you for your help.
  1 个评论
Manuel Valenciano
Manuel Valenciano 2016-6-20
I try to use the function join but I have an error:
Error using table/join (line 111)
The key variable for B must have unique values.

请先登录,再进行评论。

回答(1 个)

Peter Perkins
Peter Perkins 2016-8-3
I'm not 100% sure I've understood the operation you want to do, but it sounds like you want to find the rows in table 2 whose example1 and example2 values match the example1 and example2 values in table 1, and get those rows from table 2. You can do that using something like
i = ismember(table2(:,{'example1' 'example2'}),table1(:,{'example1' 'example2'});
table3 = table2(i,:);
That assumes all combinations are unique. If the goal is more general than that, then I think Manuel is on the right track with some form of join.

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by