MATLAB: Sorting data from table

datetable

Hi, I have a table T (8766×4) columns are – month, day, year and Flow rate (that is 24 years of data – 8766 days). I need to sort flow rate for each year separately and descend flow rate for each year and then plot.
P.S. I am afraid this approach with tables is wrong

Best Answer

T - your table with variables: month, day, year and prutok.
ii = findgroups(T.year);
Prutok = accumarray(ii,T.prutok,[],@(x){sort(x,'descend')});
for jj = 1:numel(Prutok), plot(Prutok{jj}); hold on; end
other variant
Days1 = day(datetime(T{:,{'year','month','day'}}),'dayofyear');
c = findgroups(T.year);
Anew = sort(accumarray([Days1,c],T.prutok,[],[],nan),'descend');
plot(Anew)
(added)
and the best variant by Guillaume and Peter
hold on
varfun(@(x)plot(sort(x,'descend')),T,'GroupingVariable','year','InputVariable','prutok');
hold off