Algorythm for Average of excel data
이전 댓글 표시
Dear Sir please suggest .. How can I get average of my attached data in excel at an interval of every 5 datas. like at time interval 0-0.5 sec then 0.6-1 sec, 1-1.5 sec and so on....
댓글 수: 1
You have a lot of what look like helpful answers to your question. Unless, there is something that has not been addressed in these answers, it would be good for you to now select one of them as the answer. This will allow the question to be marked as answered so that others will know that an answer is available.
채택된 답변
추가 답변 (4개)
If you have the Statistics and Machine learning toolbox you could do it like this
% Parameters
grpIncr = 0.5 % time increment for group averages
% Read the data into a matrix
dat = readmatrix('S1IA.csv')
% Provide grouping variable that makes elements within a specified sampling
% interval have the same group value
grp = floor(dat(:,1)/0.5);
[dat grp]
% Calculate mean of each group
stats = grpstats(dat(:,2:3),grp)
댓글 수: 3
Sorry, I just noticed you wanted groups "0-0.5 sec then 0.6-1 sec, 1-1.5 sec and so on..."
I assume that you actuallly mean groups 0.1-0.5 sec, 0.6-1 sec, etc, that is to be consistent the first group should start at 0.1.
The code above groups them 0-0.4, 0.5-0.9, 1-1.4, ...
If you want it to group them 0.1-0.5, 0.6-1.0 sec etc then modify the line of code that computes the group to
%grp = floor((dat(:,1)-0.1)/0.5);
So, this would give overall
% Parameters
grpIncr = 0.5 % time increment for group averages
% Read the data into a matrix
dat = readmatrix('S1IA.csv')
% Provide grouping variable that makes elements within a specified sampling
% interval have the same group value
grp = floor((dat(:,1)-0.1)/0.5);
[dat grp]
% Calculate mean of each group
stats = grpstats(dat(:,2:3),grp)
SATYA PAL
2024년 2월 21일
SATYA PAL
2024년 2월 21일
Maybe something like this:
filename = 'S1IA.csv';
T = readtable(filename);
T.Time = seconds(T.Time);
T = table2timetable(T,'RowTimes','Time');
new_t = T.Time(1):seconds(0.5):T.Time(end);
T = retime(T,new_t,'mean')
hello again
well, this is quite the same as my answer to your other post
adapted to your new data file , this becomes :
data = readmatrix('S1IA.csv'); % Time,A,B
t = data(:,1);
dt = mean(diff(t));
%% home made solution (you choose the amount of overlap)
buffer_size = round(0.5/dt); % how many samples for 0.5 seconds buffer ?
overlap = 0; % overlap expressed in samples
%%%% main loop %%%%
[new_time,data_out] = my_movmean(t,data(:,2:3),buffer_size,overlap);
figure(2),
plot(t,data(:,2),new_time,data_out(:,1),'*-r');
title('A');
legend('raw data','0.5s mean');
xlabel('Time(s)');
figure(3),
plot(t,data(:,3),new_time,data_out(:,2),'*-r');
title('B');
legend('raw data','0.5s mean');
xlabel('Time(s)');
%%%%%%%%%% my functions %%%%%%%%%%%%%%
function [new_time,data_out] = my_movmean(t,data_in,buffer_size,overlap)
% NB : buffer size and overlap are integer numbers (samples)
% data (in , out) are 1D arrays (vectors)
shift = buffer_size-overlap; % nb of samples between 2 contiguous buffers
[samples,~] = size(data_in);
nb_of_loops = fix((samples-buffer_size)/shift +1);
for k=1:nb_of_loops
start_index = 1+(k-1)*shift;
stop_index = min(start_index+ buffer_size-1,samples);
x_index(k) = round((start_index+stop_index)/2);
data_out(k,:) = mean(data_in(start_index:stop_index,:),1,'omitnan'); %
end
new_time = t(x_index); % time values are computed at the center of the buffer
end
Alexander
2024년 2월 15일
0 개 추천
A very easy approach (as allways):
%Algorythm for Average of excel data
%https://de.mathworks.com/matlabcentral/answers/2082483-algorythm-for-average-of-excel-data
clear; close all;
data = dlmread('S1IA.csv',',',1,0);
t = data(:,1);A = data(:,2);B = data(:,3);
dy = floor(length(A)/5)
t = t(1:dy*5); % maximum 4 samples lost!
tr = reshape(t,5,dy);
trMean = mean(tr);
A = A(1:dy*5); % maximum 4 samples lost!
Ar = reshape(A,5,dy);
ArMean = mean(Ar);
B = B(1:dy*5); % maximum 4 samples lost!
Br = reshape(B,5,dy);
BrMean = mean(Br);
subplot(211)
plot(trMean ,ArMean); grid minor; title('A')
subplot(212)
plot(trMean, BrMean); grid minor; title('B')
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


