find maximum value for each year in a 2 columns array

3 次查看(过去 30 天)
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)];

请先登录,再进行评论。

更多回答(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