我试图在降水数据列表中做一些修改。数据以这种格式保存在*.txt文件中:
50810,200301010600,0.0
50810,200301010601,0.0
50810,200301010800,0.0
50810,200301010938,0.1
50810,200301010947,0.1
50810,200301010957,0.1我所拥有的每个文件都包含了一年来每分钟的降水数据。第一个数字只是站号,这对于文件中的每一行都是相等的。在我的原始文件中,我每分钟都有一行数据。
我想要创建一个包含以下内容的新文件:
在if p==0条件下,我想要的格式的代码是什么?
发布于 2015-11-17 01:02:58
假设您已经将数据作为名为infile的M*3数组导入,并且M可被60除,并且您的数据从一小时的第一分钟开始,并且您有一个将被写入一个新文件的数组外部文件:
outfile = []
while ~isempty(infile)
block = infile(1:60,:); % Take one hour's worth of data
if sum (block(:,3)==0) == 60 % Check if the last column are all zero
outfile = cat(1, outfile, [block(1,1:2), 0]); % If so, put one line to new array
else
filter = block(:,3)~=0; % Otherwise, pick out only rows that the last column is not zeros
outfile = cat(1, outfile, block(filter,:)); % Put these rows into the new array
end
infile(1:60,:) = []; % Remove already processed data from original array
end然后将整个outfile数组写入文件。
https://stackoverflow.com/questions/33746352
复制相似问题