find the repeating numbers in order

1 Ansicht (letzte 30 Tage)
MakM
MakM am 9 Dez. 2021
Kommentiert: MakM am 10 Dez. 2021
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.

Akzeptierte Antwort

Dyuman Joshi
Dyuman Joshi am 9 Dez. 2021
%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)
ans = 1×7
1 2 1 4 5 7 2
  4 Kommentare
Stephen23
Stephen23 am 9 Dez. 2021
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])
ans = 1×8
0 1 2 1 4 5 7 2
MakM
MakM am 10 Dez. 2021
Thank you Stephan and Joshi.. It worked :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by