Bin data into equally spaced intervals
조회 수: 4 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!