converting values from conditional to single equation

1 回表示 (過去 30 日間)
Ali Najem
Ali Najem 2020 年 12 月 15 日
コメント済み: Ali Najem 2020 年 12 月 16 日
Hi all
I need to convert this if condition to one equation
let's assume we have this if statment
if x>=0
f = x(i);
else
f = 0.2*(exp(x)-1);
end
can I re-write if statment in one equation ?
Any suggestion would be appreciated

採用された回答

Alan Stevens
Alan Stevens 2020 年 12 月 15 日
One possibility
f = x(i)*(x(i)>=0) + 0.2*(exp(x(i)) - 1)*(x(i)<0);
  1 件のコメント
Ali Najem
Ali Najem 2020 年 12 月 16 日
Thank you so much, it worked..

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by