フィルターのクリア

Please share the algorithm of the particular data set. I want to find out average of the attached data of every 5 seconds. Thank You

2 ビュー (過去 30 日間)
Datas ain Excel are attached
  7 件のコメント
SATYA PAL
SATYA PAL 2023 年 6 月 22 日
Dear Sir
I want the averages of discrete blocks over 5-second intervals.
SATYA PAL
SATYA PAL 2023 年 6 月 22 日
but the number of data in each interval of 5 seconds are not same

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

採用された回答

Mathieu NOE
Mathieu NOE 2023 年 6 月 22 日
編集済み: Mathieu NOE 2023 年 6 月 22 日
hello
try this
data = readmatrix('Data.csv'); % Force (N),Position (mm),Time (sec)
Time = data(:,3);
t = linspace(Time(1),Time(end),size(data,1)); % recompute the time vector because the original data is rounded
dt = mean(diff(t));
%% home made solution (you choose the amount of overlap)
buffer_size = round(5/dt); % how many samples for 5 seconds buffer ?
overlap = 0; % overlap expressed in samples
%%%% main loop %%%%
[new_time,data_out] = my_movmean(t,data(:,1:2),buffer_size,overlap);
figure(2),
plot(t,data(:,1),new_time,data_out(:,1),'*-r');
title('Force');
legend('raw data','5s mean');
xlabel('Time(s)');
ylabel('(N)');
figure(3),
plot(t,data(:,2),new_time,data_out(:,2),'*-r');
title('Position');
legend('raw data','5s mean');
xlabel('Time(s)');
ylabel('(mm)');
%%%%%%%%%% 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
  3 件のコメント
Mathieu NOE
Mathieu NOE 2024 年 2 月 15 日
:)
it's a polite way to ask you to accept my answer , if , of course, it has helped you !
tahnks

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2024 年 2 月 15 日
Since you have time-based data you might want to read your data into a timetable using the readtimetable function. If you do, the retime function for timetable arrays may be useful.

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by