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

1 vue (au cours des 30 derniers jours)
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]

Réponse acceptée

Matt J
Matt J le 30 Juin 2022
Modifié(e) : Matt J le 30 Juin 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

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by