Remove rows of a table based on values in an array
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
KALYAN ACHARJYA
2019-9-25
编辑:KALYAN ACHARJYA
2019-9-25
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 个评论
Guillaume
2019-9-25
table_data(n==1, :) = []
works just as well. The find is a waste of time.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!