How to calculate average for data every nth row?
Show older comments
I have a matrix of size 900 x 9. I want to average (and find standard errors) for the data located after 30 rows. To be very clear, the first row of the resulting matrix should have the average of (1st row, 31st row, 61st row,...); then the 2nd row of the resulting matrix should have (2nd row, 302d row, 62nd row,...) and so on. Please help.
1 Comment
Arup Bhattacharya
on 28 May 2020
Answers (1)
Rik
on 26 May 2020
Something like this should do the trick:
data=rand(900,9);
row_interval=30;
avg=zeros(1,row_interval);
stderr=zeros(1,row_interval);
for n=1:row_interval
tmp=data(1:row_interval:end,:);
tmp=tmp(:);
avg(n)=mean(tmp);
stderr(n)=std(tmp);
end
Of course, you could also mean something like this:
data=rand(900,9);
row_interval=30;
avg=zeros(row_interval,size(data,2));
stderr=zeros(row_interval,size(data,2));
for n=1:row_interval
tmp=data(1:row_interval:end,:);
avg(n,:)=mean(tmp,1);
stderr(n,:)=std(tmp,1);
end
1 Comment
Arup Bhattacharya
on 28 May 2020
Categories
Find more on Time Series Events in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!