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!