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

7 Ansichten (letzte 30 Tage)
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.

Antworten (1)

Star Strider
Star Strider am 20 Feb. 2025
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 Kommentare
Siddharth Bhutiya
Siddharth Bhutiya am 20 Feb. 2025
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.
Star Strider
Star Strider am 20 Feb. 2025
@Chad
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Floating-Point to Fixed-Point Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by