Sorting data from table
10 ビュー (過去 30 日間)
古いコメントを表示
Hi, I have a table T (8766x4) 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
0 件のコメント
採用された回答
Andrei Bobrov
2018 年 10 月 15 日
編集済み: Andrei Bobrov
2018 年 10 月 18 日
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
2 件のコメント
Guillaume
2018 年 10 月 15 日
Assuming that's what is wanted, this is probably simpler:
varfun(@(col) plot(sort(col, 'descend'), T, 'GroupingVariables', 'year', 'InputVariables', 'prutok')
その他の回答 (1 件)
Guillaume
2018 年 10 月 15 日
Simple:
sortedtable = sortrows(yourtable, 'year', 'flowrate', {'ascend', 'descend'}) %sort ascending by year, and for identical year, descending by flow rate
where 'year' and 'flowrate' are the variable names of your year and flow rate column respectively.
A table is the right approach.
2 件のコメント
Peter Perkins
2018 年 10 月 17 日
I think something like Guillaume's is the right way to go: sort the data by time, then make a plot for each year. From the plot you made, it seems like your original description is not accurate -- it looks to me like you want to plot flow rate by time, overlaying each year.
So: sortrows using year/month/day, then use varfun to make the plots (with hold on/of before and after).
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
