matlabmodel.matrixdigital-ocean-spacessst

Calculate average value of SST data of a whole month


I have SST data for 30 days of one rigion. However, part of daily (several days) data is missed, as shown in the following figure. So, I want to calculate the average value of these obtained SST data for these 30 days. Since some of the days are missed.

I am wondering how can I calculate the average SST value for these 30 days? My data is in .mat format.

For example, is there any function (in Matlab or Python) I can use to calculate the average value even though some of the data are missed?

Note: the 'NaN' indicates the missed data.

Thanks in advance!

enter image description here


Solution

  • Just use the 'omitnan' flag of the mean() function.

    % 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');