Remove rows of a table based on values in an array

4 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

KALYAN ACHARJYA
KALYAN ACHARJYA il 25 Set 2019
Modificato: KALYAN ACHARJYA il 25 Set 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

Più risposte (0)

Categorie

Scopri di più su Tables in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by