Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Repetition of repeated rows

1 回表示 (過去 30 日間)
William Hynes
William Hynes 2016 年 4 月 6 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have a very large matrix (780000X2). In column 1, there is a scenario number, between 1 and 20000. I want to identify those rows which have a scenario number repeated elsewhere at least 20 times. For example, let's say I want to identify rows in Matrix A which have a scenario number repeated at least 2 times.
A= [1 22;2 23;2 24;2 25;3 26]
In this situation, I would be trying to identify (2, 23), (2,24) and (2,25).

回答 (2 件)

Star Strider
Star Strider 2016 年 4 月 6 日
This works:
A = [1 22;2 23;2 24;2 25;3 26];
[Au,ia,ic] = unique(A(:,1)); % Find unique Values In Column #1
A1h = accumarray(ic, 1); % Historgram Counts Of Those Values
Desired_Rows = A(ic == ia(A1h > 2), :) % Find All Rows With ‘ia’ Index Of Column #1 Numbers Meeting Criteria
Desired_Rows =
2 23
2 24
2 25
It first finds the unique entries in column 1, then counts them in the accumarray call, finds all those meeting criteria in the ‘ic’ output of the unique call, and uses those addresses (a logical vector here) to select and save the output of that to the ‘Desired_Result’ variable.

Robert
Robert 2016 年 4 月 6 日
There are a few ways you could do this. The most straightforward is with hist. Use hist to count the instances of your data with bins 1:20000.
values = 1:20000;
num_occurances = hist(A(:,1),values);
values(num_occurances >= 20)

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by