필터 지우기
필터 지우기

Finding an average of 1XN vector using iteration.

조회 수: 2 (최근 30일)
Kratos
Kratos 2015년 2월 18일
댓글: dpb 2015년 2월 18일
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