Calculate Mean /Average of 4D data

3 次查看(过去 30 天)
pranto saha
pranto saha 2023-3-14
回答: Aastha 2025-5-8
I have a 4D data of speed. Size is (301x246x48x119).followed by (latitude, lontitude, height, month). Now I want to calculate Mean from this data.
1st I want to mean speed to remove latitude and lontitude. And after that I want to separate the data by monthwise. After that I will mean data for month.(Here 12 month is used circularly)
Can you please Help me how can i do this?
My final target is to find 12(month) dataset where each dataset contain one speed for every height.
  2 个评论
Jan
Jan 2023-3-14
编辑:Jan 2023-3-14
You forgot the step, in which you calculate the speed from latitude and longitude.
Adam Danz
Adam Danz 2023-3-14
> each dataset contain one speed for every height
Could you provide your data? What if heights are [4.5, 4.51, 4.511,...] is that one height of 3 heights?

请先登录,再进行评论。

回答(1 个)

Aastha
Aastha 2025-5-8
As I understand, you want to compute the mean along the latitude, longitude, and month dimensions and obtain the mean speed grouped by month for each height value. You may refer to the steps mentioned below to do so:
1. Using the "mean" function in MATLAB, take the mean along the latitude and longitude dimensions, and use the "squeeze" function in MATLAB to remove singleton dimensions:
mean_speed = mean(mean(speed, 1), 2); % Size: (1, 1, height, month)
% Squeeze to remove singleton dimensions
speed_mean = squeeze(speed_mean); % Size: (height=48, month=119)
You can specify the axis over which the mean has to be computed as an input argument to the "mean" function in MATLAB. For more information on the "mean" and "squeeze" functions, please refer to the MathWorks documentation:
2. Since the 12-month indexing is used cyclically, you can group the data by month and compute a monthly average speed for each height. You may do so using the following MATLAB code snippet:
num_months = 12;
num_heights = size(speed,3);
num_month_points = size(speed,4);
monthly_vs_height_data = zeros(num_heights, num_months);
for m = 1:num_months
% Select all rows corresponding to month m (cyclic every 12)
monthly_vs_height_data (:,m) = mean(mean_speed(:,m:num_months:num_month_points),2);
end
This way, you can obtain a dataset of the average speed grouped by month for each height value.
I hope this is helpful!

类别

Help CenterFile Exchange 中查找有关 Polar Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by