0

我有一个地区 30 天的 SST 数据。但是,会丢失部分每日(几天)数据,如下图所示。所以,我想计算这 30 天获得的这些 SST 数据的平均值。因为有些日子错过了。

我想知道如何计算这 30 天的平均 SST 值?我的数据是 .mat 格式。

例如,即使丢失了一些数据,是否有任何函数(在 Matlab 或 Python 中)可以用来计算平均值?

注意:“NaN”表示丢失的数据。

提前致谢!

在此处输入图像描述

4

1 回答 1

0

只需使用 mean() 函数的 'omitnan' 标志。

% Random input array
x = rand(30, 1);

% Insert a random number of NaNs in the array
nNaN = randi(30, 1);
idx = randi(30, [nNaN, 1]);
x(unique(idx)) = NaN;

% Calculate the average
xav = mean(x, 'omitnan');
于 2021-05-25T06:39:38.387 回答