find the repeating numbers in order
조회 수: 2 (최근 30일)
이전 댓글 표시
I want to find the repeating numbers from the array in order. I have tried different repeating functions which tell me the frequency of the numbers, but I want to know the order of the repeating numbers. For example I have an array which is a=[1,1,1,1,1,2,2,2,2,2,1,1,1,1,4,4,4,5,5,5,7,7,2,2,2,2] and I want my function to give me the answer 1,2,1,4,5,7,2.
댓글 수: 0
채택된 답변
Dyuman Joshi
2021년 12월 9일
%Given your first element isn't 0
a=[1,1,1,1,1,2,2,2,2,2,1,1,1,1,4,4,4,5,5,5,7,7,2,2,2,2];
a(diff([0 a])~=0)
댓글 수: 4
Stephen23
2021년 12월 9일
A robust solution that works for any values:
a = [0,1,1,1,1,1,2,2,2,2,2,1,1,1,1,4,4,4,5,5,5,7,7,2,2,2,2];
a([true,diff(a)~=0])
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!