如何在Matlab中计算地势高度异常? [英] How to calculate anomalies of Geopotential Height in Matlab?

查看:90
本文介绍了如何在Matlab中计算地势高度异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对计算Matlab中的GPH异常感兴趣.我有纬度,经度和时间的3D矩阵.其中时间是32年(1979-2010年)的每日GPH值.矩阵为95x38x11689.在矩阵为3D的情况下,如何计算所有年份的每日平均值?

I am interested in calculating GPH anomalies in Matlab. I have a 3D matrix of lat, lon, and time. Where time is a daily GPH value for 32 years (1979-2010). The matrix is 95x38x11689. How do I compute a daily average across all years for each day of data, when the matrix is 3D?

我最终试图根据当日的每日值和气候平均值的差来计算GPH异常.

I am ultimately trying to compute the GPH anomaly from the difference of the daily value and the climatological mean of that given day.

换句话说,如何计算所有年份1月1日的平均值,以计算1979-2010年所有1月1日的气候平均值?之后的每一天,依此类推.数据还包括leap年.我该如何处理?

In other words, how do I compute the average of Jan. 1st dates for all years to compute the climatological mean of all Jan. 1st's from 1979-2010? And so forth for each day after. The data also includes leap years. How do I handle that?

谢谢!

更新:第3维是GPH数据而非时间.这只是1979年至2011年每一天的数据.

UPDATE: The 3rd dimension is the GPH data NOT time. It's just the data for every day time step from 1979 to 2011.

推荐答案

尝试如下操作:

%Using your dimensions make up some fake data
GPH = rand(95,38,11689)
%Get an index into the 3rd dimension for your desired dates
dateIdx = datenum(1979:2010,1,1)-datenum(1979,1,1) + 1;
%Take the mean along the 3rd dimensions
mean_of_all_Jan_1 = mean(GPH(:,:,dateIdx ),3);

例如,每个3月15日获取另一个任意日期的示例.请注意,我只将第一个呼叫更改为datenum,而不是第二个.

An example of getting another arbitrary date say every March 15th. Note that I only changed the first call to datenum and not the second.

dateIdx = datenum(1979:2010,3,15)-datenum(1979,1,1) + 1;
mean_of_all_March_15 = mean(GPH(:,:,dateIdx ),3);

我假设第3维索引1是1979年1月1日,每天以1个索引前进.

I am assuming that along the 3rd dimension index 1 is Jan 1 1979 & progresses at 1 index per day.

编辑以获取每天 这将返回dailyMeanGPH,即95x38x366.这样,dailyMeanGPH(:,:,1)是每个Jan 1月1日的均值,dailyMeanGPH(:,:,2)= Jan 2nd ... 请注意,在2月29日,平均天数会减少,因为它的发生频率是平均频率的1/4.

EDIT to get every day This will return a dailyMeanGPH that is 95x38x366. Such that dailyMeanGPH(:,:,1) is the mean for every Jan 1st, dailyMeanGPH(:,:,2) = Jan 2nd ... Note that for Feb 29th there will be less days averaged since it will occur 1/4th as often.

或者,如果注释/取消注释输出下方代码中指出的行,则可以在单元格数组中返回.这样,如果您想让1月1日表示您先执行dailyMeanGPH{1,1},然后执行1月2日dailyMeanGPH{1,2}等,则该单元格中的索引为感兴趣的{month,day}.

Alternative you if comment/uncomment the lines noted in the code below your output can be returned in a cell array. That way if you wanted Jan 1 mean you would do dailyMeanGPH{1,1} then Jan 2nd dailyMeanGPH{1,2} etc. Where the index into the cell is {month,day} of interest.

function dailyMeanGPH = getDailyMeanGPH(GPH)

daysInMonth = [31 29 31 30 31 30 31 31 30 31 30 31]; %inlcude 29 for Feb
dailyMeanGPH = zeros(size(GPH,1),size(GPH,2),sum(daysInMonth)); %COMMENT OUT IF YOU WNAT OUTPUT IN CELL
% dailyMeanGPH = cell(12,31); %UNCOMMENT IF YOU WANT OUTPUT IN CELL

k = 1;
for m = 1:12
    for d = 1:daysInMonth(m)
        %Get an index into the 3rd dimension for your desired dates
        dateIdx = datenum(1979:2010,m,d)-datenum(1979,1,1) + 1;        
        if m==2 && d ==29 %Purge Feb 29 from non-leap years.
            checkIdx =  datenum(1979:2010,3,1)-datenum(1979,1,1) + 1;
            dateIdx = setdiff(dateIdx,checkIdx);
        end        
         %Take the mean along the 3rd dimensions.
         dailyMeanGPH(:,:,k) = mean(GPH(:,:,dateIdx ),3);%COMMENT OUT IF YOU WNAT OUTPUT IN CELL
         k = k+1;
%          dailyMeanGPH{m,d} = mean(GPH(:,:,dateIdx ),3);%UNCOMMENT IF YOU WANT OUTPUT IN CELL     
    end
end

这篇关于如何在Matlab中计算地势高度异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆