HELP! Averaging each element in multiple matrices

1 次查看(过去 30 天)
I have 11 years of daily data in matrices with size x,y (all saved in the same folder in .txt format). I want to find the Average for each month and have it in a .txt output. The text files are named 20030101, 20030102 etc (Jan 1st and 2nd) and I need outputs with the same names or very similar e.g. add a letter so the original data is not saved over. Thus far I have this code
clear all
S = dir('Data\*.txt');
N = {S.name};
for k = 1:numel(S)
A = load(N{k});
%This is where I need a function to average the matrices for each day of a month, unsure what to do (e.g. final = mean matrices 1:30)
[~,name] = fileparts(N{k});
dlmwrite(sprintf('%s.txt',name),final)
end
I need the output to be the same dimensions as the input x,y so that the monthly matrix will be the same size as the daily inputs but with an average value in each element. I need to get around the fact that months have a different amount of days too.
Thank you in advance for any help, I am new to matlab and it is not straight forward to me
  2 个评论
Guillaume
Guillaume 2015-3-5
I'm sure I commented on the exact same question a few days ago. What happened to it?
So, I'll ask again, do you want to average all the matrix elements down to just one number
avg = mean(A(:));
which is unusual in matlab or something else? (like row or column average which is a lot more common).
Robert
Robert 2015-3-6
Hi, you're not wrong, for some reason my question was reported and deleted yesterday before I could read your comment, no idea why but thank you for your comment. To answer your question I need the output to give the average of each pixel in the matrix, so the matrix will be the same size as the input matrices but for example element 1:1,1:1 will be the average of 1:1,1:1 of the 30 odd days in a month

请先登录,再进行评论。

回答(1 个)

Chad Greene
Chad Greene 2015-3-6
You can use downsample_ts to get monthly means from daily data.

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by