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

조회 수: 1 (최근 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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by