Search in two columns (Tables)
11 次查看(过去 30 天)
显示 更早的评论
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154212/image.jpeg)
Table2_example:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154213/image.jpeg)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154215/image.jpeg)
Thank you for your help.
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!