How to calculate average for data every nth row?
Mostra commenti meno recenti
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.
Risposte (1)
Rik
il 26 Mag 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
Categorie
Scopri di più su Time Series Events in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!