MATLAB: Find min value in one column based on repeated value from another column

MATLABtable find min max

Hi
I have a large table that lists a set of data in regards to: Location, polulation, rainfall:
Locations are listed multiple times of a general area and have different rainfall amounts, i want o find the min and max for each location overall even though the locations are listed multiple times.
Data table looks like this:
Location Population rainfall
1 a 10
1 b 2
1 c 0
1 d 100
2 a 2
2 b 125
2 c 5
2 d 10
So i'm wanting my output of a new table to be something like
Location Min Max
1 0 100
2 2 125
I've tried using for loops and looking for inbuilt functions aswell as order it the set but a column but i'm having no luck

Best Answer

If your original table is T, I believe this should work:
T2 = table;
[G,T2.Location] = findgroups(T.Location);
T2.Min = splitapply(@min, T.rainfall, G);
T2.Max = splitapply(@max, T.rainfall, G);