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?
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I want to take the average of 7 rows of each column and save into next row then next 7 until the data finish in the file attached. can anyone help.
0 个评论
采纳的回答
更多回答(2 个)
Vijeta Singh Yadav
2022-7-13
编辑:Vijeta Singh Yadav
2022-7-13
arr=readmatrix("L:\data.csv",NumHeaderLines=9)
rows=size(arr,1)
for idx=1:7:rows
a=arr(idx:idx+6,:)
avg=mean(a,1)
arr(rows+idx,:)=avg;
end
Visit following links for more clarity on the functions used:
0 个评论
Harshit Gupta
2022-7-13
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!