Finding an average of 1XN vector using iteration.

2 views (last 30 days)
Kratos
Kratos on 18 Feb 2015
Commented: dpb on 18 Feb 2015
I am trying iterate a 1xN vector but I am having a hard time setting up the loop for the question below.
To do this, find the initial mean of the input vector, then remove 10 values off the front of that vector; find a second mean of the shortened vector, then calculate the relative change between those two mean values. Then treat the shortened vector as the original, and repeat those steps until the relative change is less than or equal to 0.0005.
  3 Comments
Kratos
Kratos on 18 Feb 2015
function [val per] = findSS(in)
i
while
avg1 = mean(in);
in(1:10) = [];
avg2 = mean(in);
change = (abs(avg2-avg1)/avg1);
end
val = ;
end
This is what I have so far, I just don't know what to put after while and how to get the final answer.
dpb
dpb on 18 Feb 2015
OK, after you've gotten the two averages, you need to then test the magnitude of the difference against the criterion for stopping (which you've not yet included anywhere and then, if it's less or equal you're done; otherwise set
avg1=avg2;
before the loop begins again...
I'll leave actual code mod's for you make and then we can look at next iteration of it, too... :)

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements 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!