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!