我在此表单的txt文件中有很长的降水数据列表:
50810,200301110422,0.1
50810,200301110422,0.1
50810,200301110422,0.1
50810,200301110423,0.1
50810,200301110423,0.1
50810,200301110423,0.1
50810是电台号码
200301110422/23是日期和时间
0.1是以mm为单位的沉淀量。
一个txt文件涵盖一年,并且每次有多个行具有相同的日期和时间我想要总和降水量。
所以,在这种情况下,我希望结果是:
50810,200301110422,0.3
50810,200301110423,0.3
我已经知道如何阅读txt文件并创建一个新文件。我只需要在matlab代码中添加一些内容来压缩行,并使用相同的日期和时间。
有关如何做到这一点的任何建议??
答案 0 :(得分:-1)
I presume you mean same Station and Date Time so you can sum the precipitation by location?
Iterate though each line and do a split to break each line into it's elements. E.g.:
If previous Station & Date Time = current Station & Date Time then
add the value.
else
save what you got to your new text file and proceed to the next.
OR
Copy the structure into a LIST and use some LinQ on it.
OR
Really, you'd want to chuck all this info into a SQL table and then use some aggregate queries on the table. I'd probably go down the SQL route, personally, as it makes it easier to re-extract and manipulate later on.