Boxplot and mean for selected range of temporal datasets

3 ビュー (過去 30 日間)
Adi Purwandana
Adi Purwandana 2024 年 11 月 5 日
コメント済み: Voss 2024 年 11 月 7 日
Hello there,
I have a datasets containing 3 parameters, let's say z_i as depth, HOUR as time (in numeric format), and EP as the parameter I want to check its variability over depth and time. My intention is to get the EP median, min-max, and mean for selected range of z_i for each time, and then plot them all in a box plot and mean (in one plot), with x-axis as time and y-plot is the EP (better plotted in log-10 scale as the difference is very small).
See my file attached and the illustration of the flow process as I described above below:
Thank you!
  1 件のコメント
Mathieu NOE
Mathieu NOE 2024 年 11 月 5 日
hello
have you started something ? what issue are you facing ?

サインインしてコメントする。

回答 (1 件)

Shishir Reddy
Shishir Reddy 2024 年 11 月 6 日
Hi Adi
As per my understanding, you would like to filter a dataset based on a specified depth range (‘z_i’) and calculate statistical measures (median, min, max, mean) of the parameter ‘EP’ for each hour (‘HOUR’).
From the ‘data_w.mat’ file, I see that ‘EP’ and ‘HOUR’ are matrices with 6 rows (possibly representing different observations or repetitions) and 9991 columns , while ‘z_i’ is a vector with 9991 elements, representing depth.
You can process this data in MATLAB as follows –
1. Load the data
load('data_w.mat'); % This loads EP, HOUR, and z_i
2. Filter the data
filtered_indices = (z_i >= z_min) & (z_i <= z_max); % z_min, z_max, depends on the selected range
filtered_EP = EP(:, filtered_indices);
filtered_HOUR = HOUR(:, filtered_indices);
filtered_EP = filtered_EP(:);% Flattening the matrices
filtered_HOUR = filtered_HOUR(:);
3. Compute the statistics
% Assumption – ‘unique_hours’, ‘medians’, ‘mins’, ‘maxs’, ‘means’ are declared.
for i = 1:length(unique_hours)
hour_data = filtered_EP(filtered_HOUR == unique_hours(i));
medians(i) = median(hour_data);
mins(i) = min(hour_data);
maxs(i) = max(hour_data);
means(i) = mean(hour_data);
end
4. Plotting
figure;
hold on;
boxplot(filtered_EP, filtered_HOUR, 'Colors', [0.7 0.7 0.7], 'Symbol', '');
plot(unique_hours + 1, means, 'ro-', 'LineWidth', 1.5, 'DisplayName', 'Mean');
set(gca, 'YScale', 'log');
For more information regarding the ‘boxplot’ function, kindly refer to the following documentation - https://www.mathworks.com/help/stats/boxplot.html
I hope this helps.
  8 件のコメント
Adi Purwandana
Adi Purwandana 2024 年 11 月 7 日
Solved by adding this lines:
datetimeDate = datetime(unique_hours, 'ConvertFrom', 'datenum','Format','dd/MM/yy HH:mm');
xticklabels(string(datetimeDate))
Voss
Voss 2024 年 11 月 7 日
Ah, so HOUR is actually days.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by