フィルターのクリア

While Loop

1 回表示 (過去 30 日間)
Stephen
Stephen 2011 年 11 月 27 日
I'm trying to get a loop inplace which changes the input until the output is met. For example, if b=3*n and I want b to be greater than 50 then I want n to increase by 1 until it fullfils the above critera. I know I can get n to increase using a 'while loop' (see below) but I'm pretending I don't know the final minimum value of n.
n=9;
while n<50
n=n+1;
end
n
However (as mentioned) I haven't a clue on how I alter this to work for the above mentioned equation for b.
P.S. My actual code is (obviously more complex than the equation for b but I just want to get my head around how to do this and then see if I can get it to work on my actual code.
Many thanks in advance and sorry if I'm being a dunce :P

採用された回答

Walter Roberson
Walter Roberson 2011 年 11 月 27 日
n = InitialValue;
b = YourFormula(n); %e.g., b = 3*n
while b < YourThreshold
n = n + 1;
b = YourFormula(n);
end
  2 件のコメント
Stephen
Stephen 2011 年 11 月 27 日
Thank you, I tried something similiar but I must have messed it up somehow :/ Shall now try addapting it to my actual code :D
Stephen
Stephen 2011 年 11 月 27 日
...and back ;)
Just applied it to my actual code and (With a bit of tweaking) got it to work. Works like a dream now and am very pleased with the results :D
Thank you very much for the help learning the basics!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Mobile Fundamentals についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by