フィルターのクリア

Can we make the for loop a feedback loop that stops at a certain value?

1 回表示 (過去 30 日間)
Siddharth Gopujkar
Siddharth Gopujkar 2018 年 5 月 16 日
コメント済み: Star Strider 2018 年 5 月 16 日
I'm using a for loop to check the value of a dependent variable based on an independent variable. Is there any way that when it reaches the value I want, the loop stops?
Also, can I specify a range? For example, when the value of the variable falls between 1.90 and 2.10, the loop stops and reports the value of the independent variable.

採用された回答

Star Strider
Star Strider 2018 年 5 月 16 日
編集済み: Star Strider 2018 年 5 月 16 日
For the range, an if (link) block would work.
To stop the loop, use the break (link) or return (link) functions, depending on what you want to do.
EDIT Also consider that MATLAB has a number of optimization functions that can easily do what you want.
For example, using fzero:
f = @(x) x.^2 - 16; % Find ‘x’ Where ‘x^2 = 16’
x = fzero(f, 1)
x =
4.0000
  2 件のコメント
Siddharth Gopujkar
Siddharth Gopujkar 2018 年 5 月 16 日
Thank you!
Star Strider
Star Strider 2018 年 5 月 16 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by