MATLAB: Population density matrix shrink

matrix shrink

How do you shrink a large matrix (17400×43200) of values for population density. I tried averaging but the problem is that any cell that contains water surface will be averaged wrong since the water surface is assigned value 0 and the population density will decrease. Is there a way to put a water mask?

Best Answer

You could do the following procedure
  • replace the zeros with NaN values
  • take the mean (while setting the nanflag argument to 'omitnan')
  • set the NaN values back to zero