How do I compute averages for NOAA SST data?
4 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Star Strider
2024-2-21
编辑:Star Strider
2024-2-21
T1 = readtable('ersst5.nino.mt...-20.ascii.csv', 'VariableNamingRule','preserve')
MonthlyData = accumarray(T1.MON, (1:numel(T1.MON)).', [], @(x){T1.('NINO3.4')(x)}) % Returns All Years Of Data For Each Month
MonthlyMeans = accumarray(T1.MON, (1:numel(T1.MON)).', [], @(x)mean(T1.('NINO3.4')(x))) % Returns Monthly Means For All 75 Years
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.
.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!