Data coverage per cell of 3D array

11 vues (au cours des 30 derniers jours)
Lisa Hancke
Lisa Hancke le 8 Avr 2022
Modifié(e) : Lisa Hancke le 9 Avr 2022
I have a 3D data array of size 150 x 75 x 730 (lat x lon x time (days). Data coverage for each day (3rd dimension) varies with NAN values representing no data.
How do I calculate the data coverage in each cell for the total time duration? I want to use this to select cells with suffiicient data coverage.
  1 commentaire
Lisa Hancke
Lisa Hancke le 9 Avr 2022
Modifié(e) : Lisa Hancke le 9 Avr 2022
Thanks. I used
isfinite
and then
sum
along the 3rd dimension to get the same result. Easy :)

Connectez-vous pour commenter.

Réponse acceptée

Voss
Voss le 8 Avr 2022
% create a 3D matrix data with 15000 elements
data = rand(15,10,100);
% put NaNs at 7500 random indices (which may have repeats)
data(randi(numel(data),7500,1)) = NaN;
% this many elements of data are NaN:
nnz(isnan(data))
ans = 5918
% data coverage is the total number of non-NaN elements
% at each (x,y) point, where x and y correspond to the
% first 2 dimensions of data.
% sum ~isnan(data) over the third dimension to find
% the data coverage:
data_coverage = sum(~isnan(data),3);
disp(data_coverage);
61 61 63 61 67 61 56 57 61 69 67 62 59 67 62 59 60 56 62 56 57 69 61 60 60 65 61 66 65 58 60 68 58 62 64 52 57 61 62 55 65 55 58 60 69 61 65 57 55 60 59 54 68 52 60 64 60 55 63 58 64 54 65 63 59 56 62 61 46 58 68 55 60 64 63 58 63 63 55 58 54 55 61 59 69 62 60 49 61 60 59 61 63 64 57 63 63 58 73 55 64 60 61 62 57 60 65 60 56 67 52 65 50 53 67 65 62 54 55 64 61 68 61 58 68 61 69 56 62 62 52 65 60 63 56 67 57 64 62 67 62 56 68 58 60 69 57 58 51 58
% say sufficient data coverage is >= 60 non-NaNs
has_sufficient_data = data_coverage >= 60 % using the number of non-NaNs
has_sufficient_data = 15×10 logical array
1 1 1 1 1 1 0 0 1 1 1 1 0 1 1 0 1 0 1 0 0 1 1 1 1 1 1 1 1 0 1 1 0 1 1 0 0 1 1 0 1 0 0 1 1 1 1 0 0 1 0 0 1 0 1 1 1 0 1 0 1 0 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 0 1 1 1 1 0 1 1 1 0 1 0 1 0 0 1 1 1 0 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 0 0 0 0
% which is the same as <= 40 NaNs:
has_sufficient_data = sum(isnan(data),3) <= 40 % using the number of NaNs
has_sufficient_data = 15×10 logical array
1 1 1 1 1 1 0 0 1 1 1 1 0 1 1 0 1 0 1 0 0 1 1 1 1 1 1 1 1 0 1 1 0 1 1 0 0 1 1 0 1 0 0 1 1 1 1 0 0 1 0 0 1 0 1 1 1 0 1 0 1 0 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 0 1 1 1 1 0 1 1 1 0 1 0 1 0 0 1 1 1 0 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 0 0 0 0

Plus de réponses (0)

Catégories

En savoir plus sur NaNs dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by