找到你要的答案

Q:Using Matlab to average daily data (rasters) to monthly averages

Q:用matlab每日平均数据(栅格)每月平均值

I have 2192 rasters representing daily timestep climate data (1 jan 2008-31 mar 2013), which I would like to aggregate into monthly means (i.e average all the data within a given month&year).

I can load the data into Matlab fine to create a 3D matrix, of size 110x57x2192. The 2192 represents time dimension from jan 2008-31 to 31 mar 2013.

I have tried this using numbering in excel, but I am not sure how to set the syntax right. The monthly means should idealy replace the imported daily data in the memory. My numbering in Excel has four columns: date,day, month and year. Any NA pixel is ignored and the average for the pixel based on non NA pixels for a given month.

%create monthly averages from daily data
numbering = xlsread('Numbering.xslx', B1:D2192);
month=numbering(:,2);
years=unique(year);

Here is the first three and last three row of my excel file for numbering

1/01/2008 1 1 2008
2/01/2008 2 1 2008
3/01/2008 3 1 2008
29/12/2013 29 12 2013
30/12/2013 30 12 2013
31/12/2013 31 12 2013
31/12/2013 31 12 2013

我有2192个栅格代表日常时间的气候数据(1 Jan 2008-31损坏2013),我想总成每月的手段(即平均所有数据的一个月内&;一年内)。

我可以加载数据到MATLAB可以创建一个三维矩阵,大小110x57x2192。2192个代表时间维度从一月2008-31 31损坏2013。

我已经尝试使用Excel中的编号,但我不知道如何设置语法权利。每月应理想代替记忆中的进口日常数据。我在Excel中的编号有四列:日期、日期、月份和年份。任何NA像素被忽略,并基于一个给定的月的非NA像素的像素的平均值。

%create monthly averages from daily data
numbering = xlsread('Numbering.xslx', B1:D2192);
month=numbering(:,2);
years=unique(year);

这里是我的Excel文件的编号的前三个和最后三行

1/01/2008 1 1 2008
2/01/2008 2 1 2008
3/01/2008 3 1 2008
29/12/2013 29 12 2013
30/12/2013 30 12 2013
31/12/2013 31 12 2013
31/12/2013 31 12 2013

answer1: 回答1:

Here's how I would tackle the problem:

% Getting month breaks by detecting changes in days
day=numbering(:,2); % Day column from Excel
final_idx = find(diff(day)~=1);
initial_idx = [1 ; final_idx(1:end-1)-1];

%Number of months
nom = length(final_idx);

% Pre-allocating space for monthly mean
monthlymeans = nan(110,57,nom);

% Calculating means
for ii=1:nom
    monthlymeans(:,:,ii) = nanmean(3dmatrix(:,:,initial_idx(ii):final_idx(ii)),3);
end

Note that I assumed the data is contained in a variable called 3dmatrix and the NA pixel values are actually NaN's, since I do not have access to your original data.

以下是我将如何处理这个问题:

% Getting month breaks by detecting changes in days
day=numbering(:,2); % Day column from Excel
final_idx = find(diff(day)~=1);
initial_idx = [1 ; final_idx(1:end-1)-1];

%Number of months
nom = length(final_idx);

% Pre-allocating space for monthly mean
monthlymeans = nan(110,57,nom);

% Calculating means
for ii=1:nom
    monthlymeans(:,:,ii) = nanmean(3dmatrix(:,:,initial_idx(ii):final_idx(ii)),3);
end

请注意,我假设的数据包含在一个名为3dmatrix和Na像素值其实是南的,因为我得不到你的原始数据。

matlab