How can I save the values obtain from a for loop in a nx1 vector?

x=0:996;
for x=x+4
t=datarng(x-3:x,1);
avg=sum(t)/4;
"datarng" is a variable which the data I am analyzing is being saved to. What I am doing is taking the average of every for numbers and my goal is construct a new matrix (vector) which has all the average values calculated in it. Any help is appreciated! Thanks!

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 6월 4일
avd = conv2(datarng(:,1),[1;1;1;1]/4,'valid');

댓글 수: 2

Is there a way that I can do the same thing, but for the standard deviation of every 4 numbers? Thanks so much for your help!
x = datarng(:,1);
n = 4;
nn = numel(x);
out = std(x(hankel(1:nn-n+1,nn-n+1:nn),0,2);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by