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!

 Accepted Answer

avd = conv2(datarng(:,1),[1;1;1;1]/4,'valid');

2 Comments

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);

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!