Calculate Mean /Average of 4D data

3 views (last 30 days)
pranto saha
pranto saha on 14 Mar 2023
Answered: Aastha on 8 May 2025
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 Comments
Jan
Jan on 14 Mar 2023
Edited: Jan on 14 Mar 2023
You forgot the step, in which you calculate the speed from latitude and longitude.
Adam Danz
Adam Danz on 14 Mar 2023
> 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?

Sign in to comment.

Answers (1)

Aastha
Aastha on 8 May 2025
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!

Categories

Find more on Polar Plots 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!