I have 366 matrices of size 72x144. How can I create a 367th matrix, also size 72x144, which represents the average by element of the original?
조회 수: 1 (최근 30일)
이전 댓글 표시
I asked a similar question last night, but didn't get an answer I understood. To be more specific, I have 366 matrices, each size 72x144, and each representing a day's worth of data, for a total of one year worth of daily data. The file names for the individual matrices are in the format "20040101.txt", "20040102.txt", ... "20040131.txt", "20040201.txt", etc. I would like to create a new 72x144 matrix which represents the average by element of the original 366 matrices. What is the easiest way for me to do that, keeping in mind I know very little about MATLAB.
Last night, I successfully made an average matrix for two separate months, but it took me nearly an hour to do so, because I did it the only way I understood: add all matrices manually and divide by 31, such that:
newMatrix=('20040101.txt'+'20040102.txt'...'20040131.txt')./31
How can I make this simpler? I know there is a better way, but can someone please also explain in detail what the simpler function does (how it operates) rather than just giving me the code?
Thanks,
Patrick
댓글 수: 0
채택된 답변
Walter Roberson
2013년 10월 3일
As you create read the K'th file, store the data into DailyData(:,:,K) . Then to calculate the average of each element over the 366 matrices, use mean(DailyData,3)
댓글 수: 0
추가 답변 (1개)
Kelly Kearney
2013년 10월 3일
To add to Walter's answer, here's a quick way to generate your list of file names, since they're labeled by date rather than a simple sequence of 1-366:
days = datenum(2004,1,1):datenum(2004,12,31);
files = cellstr(datestr(days, 'yyyymmdd.txt'));
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!