How to count the number of pixels having values in 3Dtime series data?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Pratyush Swain
2024-3-15
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!