Delete rows when a value repeated less than 5 times
古いコメントを表示
I have a matrix:
a b c
1 201 1
2 202 1
3 203 1
4 204 1
5 205 1
6 206 1
7 207 2
8 208 2
9 209 2
10 210 2
11 222 3
12 232 3
I would like to remove rows 7-12 which have a value in the last column (c) repeated less than 5 times. Any help is appreciated.
採用された回答
その他の回答 (1 件)
idx = unique(m(:,3));
count = accumarray(c.',(1:numel(c)).',[],@numel);
to_keep = ~ismember(m(:,3),idx(count < 5));
result = m(to_keep,:)
5 件のコメント
Dinh-Vinh Vo
2017 年 8 月 31 日
編集済み: Dinh-Vinh Vo
2017 年 8 月 31 日
José-Luis
2017 年 8 月 31 日
My bad.
c = m(:,3);
idx = unique(c);
count = accumarray(c, (1:numel(c)).',[],@numel);
to_keep = ~ismember(c,idx(count < 5));
result = m(to_keep,:)
Dinh-Vinh Vo
2017 年 8 月 31 日
José-Luis
2017 年 8 月 31 日
No, the solution is not robust. You'd need to adjust the accumarray function.
Dinh-Vinh Vo
2017 年 8 月 31 日
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!