averaging files with different dates
13 ビュー (過去 30 日間)
古いコメントを表示
hi! I have files from 1978 to 2009 every 10 days, named as follows:
1978_11.txt
1978_21.txt
. . .
2009_361.txt
2009_365.txt
I would like to average the day 11 of every year and generate a file, then the day 21 and so on, but I dont know how.
I know how to read the files (they are in the same folder, but not how to read the ones I know for the average... Can someone help me please?
thank you for your time
0 件のコメント
採用された回答
Thorsten
2016 年 8 月 16 日
編集済み: Thorsten
2016 年 8 月 16 日
years = 1978:2009
for y = years
pattern = sprintf('*_%d.txt', y);
d = dir(pattern);
Nfiles = numel(d);
average = 0;
for i = 1:numel(d)
filename = d(i).name;
% read data from filename
% insert your function here
% assume that the data is read into variable 'data'
average = average + 1/Nfiles*data;
end
average_filename = sprintf('avg_%d.txt', y);
% write data to file, e.g., using dlmwrite
dlmwrite(average_filename, average)
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!