Finding an average of 1XN vector using iteration.

1 次查看(过去 30 天)
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 个评论
Kratos
Kratos 2015-2-18
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 2015-2-18
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... :)

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by