How to sum up numbers in time series from .txt file

3 ビュー (過去 30 日間)
pink flower
pink flower 2020 年 4 月 13 日
コメント済み: pink flower 2020 年 4 月 15 日
I have a .txt file with time series matrix like this:
2014,01,29,14,04,0.200
2014,01,29,14,50,0.000
2014,01,29,15,50,0.000
2014,01,29,16,50,0.000
2014,01,29,17,50,0.000
2014,01,29,18,50,0.000
2014,01,29,19,50,0.000
2014,01,29,20,50,0.000
2014,01,29,21,50,0.000
2014,01,29,22,50,0.000
2014,01,29,23,50,0.000
2014,01,30,0,50,0.000
2014,01,30,01,15,0.787
2014,01,30,01,50,0.000
2014,01,30,01,51,0.200
2014,01,30,02,49,0.589
2014,01,30,02,50,0.200
2014,01,30,03,03,0.393
2014,01,30,03,22,7.088
2014,01,30,03,33,6.101
2014,01,30,03,44,10.358
2014,01,30,03,50,2.952
2014,01,30,03,55,1.969
2014,01,30,04,02,0.982
2014,01,30,04,09,0.200
The columns show year, month, day, hour, minute and precipitation rate, respectively. I need hourly precipitation data. I want to get output like this in a .txt file:
2014,01,29,14,0.200
2014,01,29,15,0.000
2014,01,29,16,0.000
...
And I need daily precipitation data in a other .txt file:
2014,01,29,0.200
2014,01,30,31.819
...
Tks for help!!

採用された回答

Peng Li
Peng Li 2020 年 4 月 13 日
編集済み: Peng Li 2020 年 4 月 14 日
Load it using readtable. And do a splitapply or rowfun.
tbl = readtable('test.txt', 'ReadVariableNames', 0);
tbl.Properties.VariableNames ...
= {'year', 'month', 'day', 'hour', 'minutes', 'precipationRate'};
[grp, hrTbl] = findgroups(tbl(:, {'year', 'month', 'day', 'hour'}));
hrTbl.preci = splitapply(@mean, tbl.(6), grp);
hrTbl.year = splitapply(@(x) x(1), tbl.(1), grp);
And writetable it.
writetable(hrTbl, writePath);
Similar for your month and yearly table.
  8 件のコメント
Peng Li
Peng Li 2020 年 4 月 15 日
Good to know the retime function. Powerful!
pink flower
pink flower 2020 年 4 月 15 日
Very good!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTimetables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by