Borrar filtros
Borrar filtros

Remove rows of a table based on values in an array

4 visualizaciones (últimos 30 días)
Emmanouil Barmpounakis
Emmanouil Barmpounakis el 25 de Sept. de 2019
Comentada: Guillaume el 25 de Sept. de 2019
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

Respuesta aceptada

KALYAN ACHARJYA
KALYAN ACHARJYA el 25 de Sept. de 2019
Editada: KALYAN ACHARJYA el 25 de Sept. de 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
  1 comentario
Guillaume
Guillaume el 25 de Sept. de 2019
table_data(n==1, :) = []
works just as well. The find is a waste of time.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by