Bin data into equally spaced intervals
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Colin Lavigne
le 11 Déc 2022
Commenté : Colin Lavigne
le 11 Déc 2022
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!
0 commentaires
Réponse acceptée
Chetan Bhavsar
le 11 Déc 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!