フィルターのクリア

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 Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by