Boxplot and mean for selected range of temporal datasets

조회 수: 99 (최근 30일)
Adi Purwandana
Adi Purwandana 2024년 11월 5일 11:11
댓글: Voss 2024년 11월 7일 1:25
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일 12:37
hello
have you started something ? what issue are you facing ?

댓글을 달려면 로그인하십시오.

답변 (1개)

Shishir Reddy
Shishir Reddy 2024년 11월 6일 9:13
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일 0:59
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일 1:25
Ah, so HOUR is actually days.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by