How to take an average of 7 rows of all the column and save into the following row and next 7 until the data finisih?
3 views (last 30 days)
More Answers (2)
Harshit Gupta on 13 Jul 2022
Hi, I understand that you want to create an average vector where each element is the average of all elements in consecutive 7 rows.
What you can do is reshape things so the matrix is 7 x n x m.
Each cell of this matrix will now consist of 7 numbers in a column that you want to average.
Then you would take the mean of each column of that matrix. The result would be 1 x n x m, and we will have averaged the 7 elements in each column together that you wanted averaged. Now we can take average of each row and that would create the desired result that you want
Here's an example:
M = [1:2401];
M = reshape(M, 49, 49); % Dummy matrix of 49 x 49 dimensions
% Now we reshape the matrix into 7 x 7 x 49, and use the squeeze function
% to get back a 7 x 49 matrix, which contains average of 7 consecutive
% numbers in a column
B = squeeze(mean(reshape(M,[7,7,49]),1))
% Now we take average of each row
C = mean(B')
I've haven't used data from your excel sheet but if you are able to read the data from your excel sheet and make a matrix like the one used above, then this should work.
Refer to these documentation links to learn more about the functions used here: squeeze, reshape, mean
Hope this helps!