Clear Filters
Clear Filters

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

1 view (last 30 days)
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;
any help would be great

Accepted Answer

Star Strider
Star Strider on 4 Oct 2021
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.
Star Strider
Star Strider on 4 Oct 2021
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 on 4 Oct 2021
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;

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!