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

1 view (last 30 days)
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]

Accepted Answer

Matt J
Matt J on 30 Jun 2022
Edited: Matt J on 30 Jun 2022
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

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!