MATLAB: Delete rows when a value repeated less than 5 times

duplicated values

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.

Best Answer

m = [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];
% Unique elements and locations in third column
[uv, ~, id] = unique(m(:,3));
% How many of each?
n = histcounts(id);
% Keep ones with more than 5.
m2 = m(ismember(m(:,3), uv(n>=5)),:)