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.
0 个评论
回答(1 个)
Star Strider
2025-2-20
5 个评论
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),:)
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.
Star Strider
2025-2-20
另请参阅
类别
在 Help Center 和 File 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!