Filtering a Single Column of One Table Based on Multiple Criteria from Another Table.

7 次查看(过去 30 天)
To start I am working on a different network and unable to show my code and will do my best to explain.
I have 2 tables (Table A starts at 130x19, Table B starts at 5000x8) that share a single variable header that contains ID numbers. I have successfully filtered down table A to 10x19. What I am having trouble doing currently is taking those 10 ID numbers to filter table B to show all rows (with all information) that have any of the unique 10 IDs.

回答(1 个)

Star Strider
Star Strider 2025-2-20
I’m not sure that I fully understand your problem, however the join function (or one of its friends innerjoin or outerjoin) may be the solution.
  5 个评论
Siddharth Bhutiya
Siddharth Bhutiya 2025-2-20
If you only want the data from the data1 table then as Star Strider suggested above, using ismember + subscripting will also do the trick.
data1 = table(["A"; "B"; "C"; "D"; "E"; "A"; "C"], [1; 2; 3; 4; 5; 6; 7], 'VariableNames', {'Category', 'Value'});
data2 = table(["A"; "C"], 'VariableNames', {'Category'});
filteredData = data1(ismember(data1.Category, data2.Category),:)
filteredData = 4x2 table
Category Value ________ _____ "A" 1 "C" 3 "A" 6 "C" 7
Basically what the expression means is give me all the rows from data1 where data1's Category matches one of data2's Categories, which I believe is what you want.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Floating-Point to Fixed-Point Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by