Mean value every 60 rows
이전 댓글 표시
Hello, I got my table, with 180 rows and 2 columns, each column is a variable X1, X2. I want to have the mean of X1 60 rows in 60 rows, the same for X2. This is the result media =
60.1635
60.1523
60.1492
media =
513.0252
513.1533
513.1119
Question 1) How to store the results in a matrix or table 3x2 so I would have something like:
60.1635 513.0252
60.1523 513.1533
60.1492 513.1119
Question 2) For example if i wanted to make the average each 120 rows, what would I need to change? is just the "n" value? because i dont understand what does the "1" do in here
a = reshape(tabela(:,j),[],1);
Code is here:
n = 60
for j=1:2
a = reshape(tabela(:,j),[],1);
media = arrayfun(@(i) mean(tabela(i:i+n-1,j)),1:n:length(a)-n+1)'
end
Thanks for your help!
채택된 답변
추가 답변 (2개)
Simpler:
No need to use loops/arrayfun or cellfun at all. Simpler solution is to use just reshape with mean,
cc = reshape(mean(reshape(dummy,n,[])),[],2)
cc =
60.1635 513.0252
60.1523 513.1533
60.1492 513.1119
댓글 수: 5
Tiago Dias
2018년 2월 22일
KL
2018년 2월 22일
The answer shown above is 3x2 matrix of double!
Tiago Dias
2018년 2월 23일
KL
2018년 2월 23일
That's an example Tiago! You should replace dummy with your matrix.
Tiago Dias
2018년 2월 23일
sura Naji
2019년 10월 25일
0 개 추천
l have amatrix contact from 1 colum and 1000 rows l want to find the mean and the standard deviation also l want to find the worst value of this because l use the particle swarm optimization
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!