sorting and re-allocating rainfall data held in a 3D array
2 次查看(过去 30 天)
显示 更早的评论
I have a year's worth of rainfall data (P) stored in a 3D array.
Size of P is 200 x 200 x 365. Each page represents rain on a single day.
For each location the annual rainfall is correct but there are too many rainy days.
I want to estimate the true number of rainy days by taking the annual rainfall at each location and dividing it by 10. For example, if a location has 432 mm of rain in a year I can assume it has 43 days (432 x 0.1) rainy days.
Then I want to take the sum of all the rainfall from the least rainy days (365 - 43 days) and spread it equally over the 43 most rainy days.
So far I have managed to sort the P array;
[P_sorted,I] = sort(P,3, 'descend'); % sort rainfall (B) and obtain index (I)
What I think I need to do next is find a 2D array that contains the rainfall for the least rainy day (i.e, the 43th rainy day in the example) for each location but I haven't found the solution so far. What is making it harder is the annual rainfall varies from location to location.
Any suggestions/help welcomed. Thanks so much.
Rob
0 个评论
回答(1 个)
Udit06
2023-9-8
Hi Rob,
I understand you are facing issues while redistributing the sum of rainfall from the least rainy days to the most rainy days. You can follow the following steps to do the same:
Step 1: Calculate the Annual Rainfall for Each Location
annual_rainfall = sum(P, 3);
Step 2: Estimate the True Number of Rainy Days
estimated_rainy_days = uint16(annual_rainfall ./10);
Step 3: Sort the rainfall data.
[P_sorted, I] = sort(P, 3, 'descend');
Step 4: Redistribute the Rainfall
total_days = 365;
for i = 1:size(P_sorted, 1)
for j = 1:size(P_sorted, 2)
% Calculate the sum of rainfall for the least rainy days
least_rainy_sum = sum(P_sorted(i, j, (estimated_rainy_days(i, j)+ 1):total_days));
% Calculate the average rainfall to be redistributed
least_rainy_average = least_rainy_sum / estimated_rainy_days(i, j);
% Redistribute the rainfall to the most rainy days
for k = 1:estimated_rainy_days(i, j)
P_sorted(i, j, k) = P_sorted(i, j, k) + least_rainy_average;
end
end
end
I hope this helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!