フィルターのクリア

How do I get the maximum of repetitive elements in certain portions of a matrix?

3 ビュー (過去 30 日間)
I have a 2000x2 matrix, and "for each 10x2 segment of this matrix", I need to calculate the maximum of corresponding values (second column) of repetitive values (first column) in the matrix. Like if the 3rd 10x2 segment of the matrix is this:
...
[2 20;
2 30;
2 40;
7 100;
7 110;
7 120;
7 130;
7 140;
15 240;
15 260]
...
I want to get this:
...
[2 40;
7 140;
15 260]
...
And so on. I have written the following but it gives me the maximum of repetitive elements through the "whole matrix":
[uv,~,idx] = unique(A(:,1));
B = [uv accumarray(idx,A(:,2),[],@max)];
But again, I need to do this "for each separate 10x2 segments of the matrix", and then store the results in a 'whatever x 2' sized matrix! Does anyone have any ideas how I could do this?

採用された回答

Star Strider
Star Strider 2018 年 1 月 18 日
The only way I can see to do this is with a loop that selects and analyses each 10-row segment.
This works:
A = [2 20;
2 30;
2 40;
7 100;
7 110;
7 120;
7 130;
7 140;
15 240;
15 260
4 20;
4 30;
4 40;
10 100;
10 110;
10 120;
16 130;
16 140;
25 240;
25 260
4 20;
4 30;
4 40;
10 100;
10 110;
10 120;
16 130;
16 140;
25 240;
25 260];
for k1 = 1:10:size(A,1)
T = A(k1:k1+9,:);
[uv,~,idx] = unique(T(:,1));
B{ceil(k1/10)} = [uv accumarray(idx,T(:,2),[],@max)]; % Output Cell Array
end
It seems to do what you want.
  4 件のコメント
Antonio
Antonio 2018 年 1 月 18 日
@Star Strider Great, thanks a bunch!
Star Strider
Star Strider 2018 年 1 月 18 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by