How to remove numbers that only show up once in a list of recurring numbers

조회 수: 6 (최근 30일)
Shyam Patel
Shyam Patel 2019년 7월 25일
답변: TADA 2019년 7월 25일
I have a list of numbers that goes something like this but much longer:
1,1,1,1,2,3,3,3,3,4,5,5,5,5,6,7,7,7,7,7,7,8,....,53,54,54,54,54,54
I tried to use histcount to remove all the numbers that show up only once, but it did not work (I pasted the code below). The main reason I am having an issue with this is because the intervals of same numbers are different, for example 1 shows four times while 7 shows up six times. I've also attempted indexing but I could not figure out how to properly index something like this without returning wierd values in the index vector.

답변 (1개)

TADA
TADA 2019년 7월 25일
x = [1,1,1,1,2,3,3,3,3,4,5,5,5,5,6,7,7,7,7,7,7,8,53,54,54,54,54,54];
numbers = 1:max(x);
numx = accumarray(x(:), 1);
atLeast2 = numbers(numx >= 2);
x2 = x(ismember(x,atLeast2))

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by