MATLAB: Number of non-nan values across each element in n-dimensional matrix

countn-dimensional matrix

Hello all,
I would like to know how to count the number of non-nan values across each element in a 192x144x8766 matrix. Where the dimensions is representative of days (8766 days). I want a final matrix with the number of non-Nan values for each element across all 8766 days.
For example, count of # of non-nan in 1x1x1:8766 so that I can get a fraction of non-nan values over the 8766 days per element (cell in the matrix).
Thank you for any help on this.

Best Answer

Is this what you want?
x = your 192x144x8766 array
result = sum(~isnan(x),3);