Bin data into equally spaced intervals

4 ビュー (過去 30 日間)
Colin Lavigne
Colin Lavigne 2022 年 12 月 11 日
コメント済み: Colin Lavigne 2022 年 12 月 11 日
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!

採用された回答

C B
C B 2022 年 12 月 11 日
% 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
  1 件のコメント
Colin Lavigne
Colin Lavigne 2022 年 12 月 11 日
Thank you!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by