Remove rows of a table based on values in an array

3 views (last 30 days)
I want to remove all rows from a table, when a value in table.variable appears only once.
For example
table:
var1 | var2 | var3
1 | 2 | 0
1 | 2 | 3
1 | 2 | 3
1 | 2 | 8
4 | 5 | 8
1 | 2 | 9
should become
var1 | var2 | var3
1 | 2 | 3
1 | 2 | 3
1 | 2 | 8
4 | 5 | 8

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 25 Sep 2019
Edited: KALYAN ACHARJYA on 25 Sep 2019
disp('Original table');
var1=[1;1;1;1;4;1];
var2=[2;2;2;2;5;2];
var3=[0;3;3;8;8;9];
table_data=table(var1,var2,var3)
n=histc(var3(:),var3);
disp('Updated table');
table_data(find(n==1),:)=[]
Result Window:
Original table
table_data =
6×3 table
var1 var2 var3
__ ____ ____
1 2 0
1 2 3
1 2 3
1 2 8
4 5 8
1 2 9
Updated table
table_data =
4×3 table
var1 var2 var3
____ ____ ____
1 2 3
1 2 3
1 2 8
4 5 8

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!