I am calculating nanmean using two different techniques. I have a matrix avg_terra_aqua1 of size 28*360000. In the first method, I am calculating nanmean of the matrix along its first dimension as follow:
sp_aod1 = nanmean(avg_terra_aqua1, 1);sp_aod1_modis = reshape(sp_aod1, [400, 900]);
Using the second method, I am calculating nanmean in a slightly more indirect way as follows:
nan_mat = isnan(avg_terra_aqua1);count = squeeze(sum(nan_mat, 1)); for j = 1:360000; if(count(1, j) < 29); sp_aod(1, j) = nanmean(avg_terra_aqua1(1, j), 1); else sp_aod(1, j) = NaN; end; end; sp_aod_modis = reshape(sp_aod, [400, 900]);
I expect the results of sp_aod1_modis and sp_aod_modis to be similar, because in the second method, all the count values are below 29 (it is a dataset for the month of february which has 28 days). However I am getting very different results — I have attached the results of two methods. First figure is the result of second method and second figure is the result of the first method. Can someone explain why this is happening?
Best Answer