Creating a set range for a function

10 ビュー (過去 30 日間)
Sebastian Sunny
Sebastian Sunny 2021 年 12 月 3 日
コメント済み: Alan Stevens 2021 年 12 月 3 日
Hi guys,
Im trying to create a if fucnction where my equation works for a set range of x values.
My code at the moment:
x = (mydata);
if (x < 3) && (x > 25)
windTurbineRotorModel(x == 0);
elseif (3 < x) && (x < 11)
windTurbineRotorModel = (0.042)*(1/2)*(1.23)*pi()*((171/2)^3)*(x).^2;
elseif (11 < x) && (x < 25)
windTurbineRotorModel = (0.042)*(1/2)*(1.23)*pi()*((171/2)^3)*(x).^2;
end
Thanks

採用された回答

Alan Stevens
Alan Stevens 2021 年 12 月 3 日
(x < 3) && (x > 25)
An individual element of x can't be both less than 3 and greater than 25 at the same time.
If here are many values of x (as is likely), then do the tests element by element. e.g. something like:
for i = 1:numel(x)
if (x(i) < 3) || (x(i) > 25)
windTurbineRotorModel(x == 0);
elseif (3 < x(i)) && (x(i) < 11)
windTurbineRotorModel = (0.042)*(1/2)*(1.23)*pi()*((171/2)^3)*(x(i)).^2;
elseif (11 < x(i)) && (x(i) < 25)
windTurbineRotorModel = (0.042)*(1/2)*(1.23)*pi()*((171/2)^3)*(x(i)).^2;
end
end
  2 件のコメント
Sebastian Sunny
Sebastian Sunny 2021 年 12 月 3 日
That makes alot more sense thank you
but in your code what does te numel(x) mean?
Alan Stevens
Alan Stevens 2021 年 12 月 3 日
numel(X) is the number of elements in X.

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by