How do I compute averages for NOAA SST data?

13 ビュー (過去 30 日間)
Jessica Marie
Jessica Marie 2024 年 2 月 20 日
編集済み: Star Strider 2024 年 2 月 21 日
Hello,
I am new to Matlab and new to coding entirely. I need to compute NINO3.4 SST climatological values (averages for specific time stamps, say, average over all January, February, …, December) for each month and plot the climatological result (i.e., average values of NINO3.4 SST for the 12 months).
I have no idea how to do this. Can someone please help.

回答 (1 件)

Star Strider
Star Strider 2024 年 2 月 21 日
編集済み: Star Strider 2024 年 2 月 21 日
The easiest way to do this is to use the accumarray function —
T1 = readtable('ersst5.nino.mt...-20.ascii.csv', 'VariableNamingRule','preserve')
T1 = 889x10 table
YR MON NINO1+2 ANOM NINO3 ANOM_1 NINO4 ANOM_2 NINO3.4 ANOM_3 ____ ___ _______ _____ _____ ______ _____ ______ _______ ______ 1950 1 23.01 -1.55 23.56 -2.1 26.94 -1.38 24.55 -1.99 1950 2 24.32 -1.78 24.89 -1.52 26.67 -1.53 25.06 -1.69 1950 3 25.11 -1.38 26.36 -0.84 26.52 -1.8 25.87 -1.42 1950 4 23.63 -1.9 26.44 -1.14 26.9 -1.73 26.28 -1.54 1950 5 22.68 -1.74 25.69 -1.57 27.73 -1.18 26.18 -1.75 1950 6 21.33 -1.79 25.51 -1.11 28.13 -0.84 26.46 -1.27 1950 7 20.31 -1.65 24.91 -0.9 27.64 -1.26 26.29 -1.01 1950 8 20.12 -0.88 24.47 -0.65 27.54 -1.25 25.88 -0.97 1950 9 19.56 -1.17 24.01 -0.89 27.27 -1.49 25.74 -0.98 1950 10 19.99 -1.02 24.17 -0.81 27.13 -1.63 25.69 -1.03 1950 11 19.85 -1.8 23.86 -1.24 26.99 -1.7 25.47 -1.23 1950 12 21.72 -1.09 24.15 -1.08 27.14 -1.4 25.29 -1.31 1951 1 24.11 -0.46 24.79 -0.87 27.21 -1.1 25.24 -1.3 1951 2 25.19 -0.91 25.65 -0.76 27.09 -1.11 25.71 -1.04 1951 3 25.74 -0.75 26.87 -0.33 27.74 -0.58 26.9 -0.38 1951 4 25.29 -0.25 27.37 -0.21 28.21 -0.42 27.58 -0.23
MonthlyData = accumarray(T1.MON, (1:numel(T1.MON)).', [], @(x){T1.('NINO3.4')(x)}) % Returns All Years Of Data For Each Month
MonthlyData = 12x1 cell array
{75x1 double} {74x1 double} {74x1 double} {74x1 double} {74x1 double} {74x1 double} {74x1 double} {74x1 double} {74x1 double} {74x1 double} {74x1 double} {74x1 double}
MonthlyMeans = accumarray(T1.MON, (1:numel(T1.MON)).', [], @(x)mean(T1.('NINO3.4')(x))) % Returns Monthly Means For All 75 Years
MonthlyMeans = 12x1
26.4279 26.6104 27.1176 27.5719 27.6912 27.5139 27.0877 26.6761 26.5666 26.5354
figure
plot((1:12), MonthlyMeans)
grid
xlabel('Month Number')
ylabel('NINO3.4 Mean (°C)')
xlim([1 12])
set(gca,'XTick',(1:12))
Since you appear to be completely new to all of this, the approach here is to use accumarray (an efficient looping algorithm that aggregates data) to select the months of each year and then return the data from them. Here, the index vector are the months (the table format for these data makes this extremely convenent), and it then uses a vector for all the indices to aggregate them (the second argument). (The third argument is not necessary here, however since it needs to be supplied, common practics is to use the empty array [] in such instances.) The last argument is an anonymous function (see the documentation section on Anonymous Functions) that tells accumarray what to do with the data. In the first call to it, the purpose is to return all the data for all years for each month in a cell array. The second and completely separate call to it, calculates the monthly means over all the years and returns them as a single vector. I include both of them to illustrate different ways of using it, however for the present purpoose, only the second call to it is necessary.
EDIT — Corrected typographical errors. Code unchanged.
.

カテゴリ

Help Center および File ExchangeWeather and Atmospheric Science についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by