필터 지우기
필터 지우기

HELP! Averaging each element in multiple matrices

조회 수: 1 (최근 30일)
Robert
Robert 2015년 3월 5일
댓글: Robert 2015년 3월 6일
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