How to count the number of pixels having values in 3Dtime series data?
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Pratyush Swain
on 15 Mar 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.
More Answers (0)
See Also
Categories
Find more on NaNs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!