Bin data into equally spaced intervals

4 views (last 30 days)
From an excel sheet, I would like to average the data into 24 equally spaced bins from a particular column. The bins I want to create would list the average of every 60 rows, interspered between 30 rows (i.e., mean of rows 1-60, 91-150, etc., where 61-89, 151-179, etc. are omitted). How can I program this?
New MATLAB user here and learning.
Thank you!

Accepted Answer

C B
C B on 11 Dec 2022
% Import data from Excel sheet
data = xlsread('data.xlsx');
% Preallocate array for binned data
binned_data = zeros(24,1);
% Loop through rows of data, calculating average for each bin
bin_size = 60; % Number of rows per bin
skip_size = 30; % Number of rows to skip between bins
num_bins = size(data,1)/(bin_size+skip_size);
for i = 1:num_bins
% Calculate start and end rows for current bin
start_row = (i-1)*(bin_size+skip_size) + 1;
end_row = start_row + bin_size - 1;
% Calculate average of data in current bin
binned_data(i) = mean(data(start_row:end_row));
end

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!