How to count the number of pixels having values in 3Dtime series data?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Vedanta
el 15 de Mzo. de 2024
Comentada: Vedanta
el 17 de Mzo. de 2024
Hello everyone,
I have 3D time series data (180 x 360 x 120), where 180 is latitude, 360 is longitude and 120 is number of months.
For every month, I want to count how many pixels are having values because in every month data is not available for all the 180x360 pixels.
For example: In january there are 100 pixles having data, feb = 115, march = 1224, april = 447, may = 995
Accordingy my 2D output will be : Out = [100 115 1224 447 995];
Thanks
0 comentarios
Respuesta aceptada
Pratyush Swain
el 15 de Mzo. de 2024
Hello Vedanta,
Given that you have a 3D time series data and you want to create a 2D output containing count of valid pixel values each month, you can refer to following example implementation:
% Assuming data of 3D timeseries is of dimension: 180 x 360 x 12 --> 12 is referring to the number of months here
% Example timeseries object with random data %
ts = timeseries(rand(180, 360, 12))
% Accessing Data property %
data=ts.Data;
% Introducing some NaNs as an example of missing data %
data(data < 0.5) = NaN;
% Preallocate the output array for performance
Out = zeros(1, size(data, 3))
% Loop through each month and count non-NaN pixels
for month = 1:size(data, 3)
% Count the number of non-NaN elements for the current month
Out(month) = sum(~isnan(data(:, :, month)), 'all');
end
% Display the result
disp(Out);
For more information please refer to following resources:
Hope this helps.
Más respuestas (0)
Ver también
Categorías
Más información sobre NaNs en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!