how to range data and find maximum value for each range by using loop

1 回表示 (過去 30 日間)
abdullah al-dulaimi
abdullah al-dulaimi 2022 年 6 月 30 日
AB=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; 10 5 7 8 3 18 20 3 6 66 2 14 39 40 4 20]
AB=transpose(AB)
I have data (AB) consisting of two columns. The number of rows of this data is 16. I want to divide this number into (1: 4: 16) and take the maximum values for each period ''depend on second column'' (with index firsr column), also i want to index the firt colum).
so the results will be,
[1 10
7 20
10 66
14 40]

採用された回答

Matt J
Matt J 2022 年 6 月 30 日
編集済み: Matt J 2022 年 6 月 30 日
AB=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; 10 5 7 8 3 18 20 3 6 66 2 14 39 40 4 20].';
[maxval,i]=max(reshape(AB(:,2),4,[]),[],1,'linear');
result = [AB(i,1),maxval(:)]
result = 4×2
1 10 7 20 10 66 14 40

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by