HELP! Averaging each element in multiple matrices

2 views (last 30 days)
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 Comments
Guillaume
Guillaume on 5 Mar 2015
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 on 6 Mar 2015
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

Sign in to comment.

Answers (1)

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

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!