Reputation: 29
I have an input vector like:
[1.3, 2.2, 2.3, 4.2, 5.1, 3.2, 5.3, 3.3, 2.1, 1.1, 5.2, 3.1]
I would then like to check whether x.1 and x.2 and x.3 and x.y is in the vector and then discard if there isn't at least 3 y values with matching x values exist. So the example vector would look like:
[2.2, 2.3, 5.1, 3.2, 5.3, 3.3, 2.1, 5.2, 3.1]
(1.3
, 1.1
, and 4.2
are removed due to only 2 and 1 x value). It has to work for a vector of any length. I just started to try learn Matlab from a guide but I simply cant complete this question :(
Upvotes: 0
Views: 51
Reputation: 112689
You can
x
;x
associate its corresponding number of times;x
whose integer part occurs at least n=3
times.Code:
x = [1.3 2.2 2.3 4.2 5.1 3.2 5.3 3.3 2.1 1.1 5.2 3.1]; %// data
n = 3; %// min required number
xf = floor(x); %// step 1
[ii, jj] = histc(xf, unique(xf)); %// step 2
result = x(ismember(jj, find(ii>=n))); %// step 3
Upvotes: 2