필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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.
Thanks in advance,
Alessandro
  댓글 수: 2
Matt J
Matt J 2021년 1월 20일
And i want to store the indexes corresponding to the erased 10+-times recurrent values.
If I have a repitiion of a number, say [2 2 2 2 2] and I reduce it to [2,2,2,2] clearly I have erased one of the 2's. But which one? The first? The last? One of them in the middle?
Alessandro Togni
Alessandro Togni 2021년 1월 20일
편집: Alessandro Togni 2021년 1월 20일
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
Matt J 2021년 1월 20일
편집: Matt J 2021년 1월 20일
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))];
discard=(cumsum(b)>10); %indices to discard
a_short=a(~discard) %truncated version of a
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by