Table row retrieval with dependent on column values
Ältere Kommentare anzeigen
I am dealing with a sorting issue on a table which. The table looks like follows:
Rec_id =[1; 1; 2; 2; 2; 3; 3; 4; 4]; % for clarification: the values here go up to 80 in the original table
Rec_type= {'A';'B';'A';'B';'C';'A';'C';'A';'B'};
data_table = table(Rec_id, Rec_type)
From this I'm trying to extract all rows of Rec_id's which have Rec_type='B', but also the rows of the same Rec_id with Rec_type='A'.
The table i try to extract from the former should look like this:
Rec_id =[1; 1; 2; 2; 4; 4]; % Rec_id = 3 gets filtered out completely, since there is no Rec_id = 3 with Rec_type 'B'
Rec_type= {'A';'B';'A';'B';'A';'B'};
new_table = table(Rec_id, Rec_type)
My approach was to find all Rec_id's that have a Rec_type of 'B' and use these.
Ids_corr_to_type_B = table.Rec_id(table.Rec_type == 'B');
But I was unable to use the array retrieved from that operation successfully.
Thank you for your help!
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Tables finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!