averaging files with different dates

13 ビュー (過去 30 日間)
Maite M.
Maite M. 2016 年 8 月 16 日
コメント済み: Maite M. 2016 年 8 月 16 日
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

採用された回答

Thorsten
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
  1 件のコメント
Maite M.
Maite M. 2016 年 8 月 16 日
thank you it is what I need :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by