HELP! Averaging each element in multiple matrices
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Guillaume
am 5 Mär. 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).
Antworten (1)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!