フィルターのクリア

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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by