find maximum value for each year in a 2 columns array

조회 수: 9 (최근 30일)
Mahtab Moalemi
Mahtab Moalemi 2020년 4월 16일
댓글: Mahtab Moalemi 2020년 4월 16일
I have an array with two columns, column one year (1975-2020) and column two discharge values. I need to find the maximum discharge amount for each year and have them saved in another matrix.
Can you please help me with this?
input:
1975 200
1975 85
.
.
.
2002 110
2002 95
2002 32
...
2020 120
...
desired output
1975 200
...
2002 110
...
2020 120

채택된 답변

Tommy
Tommy 2020년 4월 16일
Try this:
[G, y] = findgroups(input(:,1));
output = [y splitapply(@max, input(:,2), G)];
  댓글 수: 5
Tommy
Tommy 2020년 4월 16일
편집: Tommy 2020년 4월 16일
Switch the outputs.
[groups, years] = findgroups(year_Q(:,1));
>> output = [years splitapply(@max, year_Q(:,2), groups)];
Mahtab Moalemi
Mahtab Moalemi 2020년 4월 16일
nevermind! sorted it out
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by