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

1 visualización (últimos 30 días)
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]

Respuesta aceptada

Matt J
Matt J el 30 de Jun. de 2022
Editada: Matt J el 30 de Jun. de 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

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by