Average the every 40 rows from csv file until finish and save the data in new csv files

1 回表示 (過去 30 日間)
Hi,
I am completely stuck here and do not know how to proceed. Basically, I am reading the sensor data from the excel which have a 40 repetition every second. I want to take a average of 40 repetition and save into separate file, data is for like 20 mins. Below is the code I am trying but can't think from an hour how to proceed further.
a = readmatrix('firsttest_2_try.csv');
x = a (:,1);
y = a (:,3);
counter = 0
for i = 1 : length(x)
counter = counter+i;
end
any help would be great

採用された回答

Star Strider
Star Strider 2021 年 10 月 4 日
I have no idea what you want to do.
If you want to take the mean of the 1 second blocks (and you have the Signal Ptocessing Toolbox), use the buffer function separately on ‘x’ and ‘y’., then take the mean of the resulting matrix across dimension #1 (columns).
Calculate the number of samples as:
NrSamples = Fs*sec;
where ‘Fs’ is the sampling frequency and ‘sec’ is the number of seconds.
If you want to take the mean using a window of that length, use the movmean function.
.
  2 件のコメント
Star Strider
Star Strider 2021 年 10 月 4 日
muhammad choudhry’s Answer became this Comment —
I just want to take the average of rows in the excel file by 40 until the number of rows finish and save into df file.
Star Strider
Star Strider 2021 年 10 月 4 日
Use the buffer function. If you so not have the Signal Processing Toolbox, use this simple emulation of it —
x = randi(9, 1, 11);
r = 4;
Q1 = buffer(x,r) % Original
Q1 = 4×3
3 1 2 4 4 9 7 1 3 9 9 0
Q2 = bufr(x,r) % Emulation
Q2 = 4×3
3 1 2 4 4 9 7 1 3 9 9 0
function M = bufr(s,r)
% s = Signal Vector
% r = Desired number of rows
M = zeros(r,ceil(numel(s)/r));
M(1:numel(s)) = s;
end
.

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

その他の回答 (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