Filter löschen
Filter löschen

find maximum value for each year in a 2 columns array

1 Ansicht (letzte 30 Tage)
Mahtab Moalemi
Mahtab Moalemi am 16 Apr. 2020
Kommentiert: Mahtab Moalemi am 16 Apr. 2020
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

Akzeptierte Antwort

Tommy
Tommy am 16 Apr. 2020
Try this:
[G, y] = findgroups(input(:,1));
output = [y splitapply(@max, input(:,2), G)];
  5 Kommentare
Tommy
Tommy am 16 Apr. 2020
Bearbeitet: Tommy am 16 Apr. 2020
Switch the outputs.
[groups, years] = findgroups(year_Q(:,1));
>> output = [years splitapply(@max, year_Q(:,2), groups)];
Mahtab Moalemi
Mahtab Moalemi am 16 Apr. 2020
nevermind! sorted it out
Thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by