# Sort a n array for maximum number of recurring values and storing the indexes corresponding to erased components

1 view (last 30 days)
Alessandro Togni on 20 Jan 2021
Edited: Matt J on 20 Jan 2021
Hi,
i'm working with an array of thousands of elements and i've to limit the repeated values to 10.
Let say:
a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9];
has to become:
[0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,9].
And i want to store the indexes corresponding to the erased 10+-times recurrent values.
Any suggestion would be appreciated.
Alessandro
##### 2 CommentsShowHide 1 older comment
Alessandro Togni on 20 Jan 2021
The 10th, 11th, etc of each list of 10+ occurrences!
Could be useful to say that i have to edit other vector of the same lenght in the same way on the one we're talking about.

Matt J on 20 Jan 2021
Edited: Matt J on 20 Jan 2021
a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9];
s=diff([inf,a])~=0;
b=ones(size(a));
b(s)=b(s)-[0,diff(find(s))];
a_short = 1×28
0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 9